๐ŸŒธ [String] , [StringBuilder]

0
post-thumbnail

  • ์ด ๊ธ€์€ ํ•˜๋“œ๋Ÿฌ๋„ˆ๋‹˜์˜ ์ž๋ฐ” StringBuilder ์‚ฌ์šฉ๋ฒ• ๋ฐ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๊ธ€์˜ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค.

์ง€์‹๊ณผ ๊ฟ€ํŒ์ด ๋„˜์น˜๋Š” "ํ•˜๋“œ๋Ÿฌ๋„ˆ"๋‹˜์˜ ๋ธ”๋กœ๊ทธ ๋ฐฉ๋ฌธํ•˜๊ธฐ

"์ž๋ฐ” StringBuilder ์‚ฌ์šฉ๋ฒ• ๋ฐ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ " ๊ธ€ ๋ณด๋Ÿฌ๊ฐ€๊ธฐ


๐Ÿ”น String

  • String์ด ๋ฌธ์ž์—ด ๊ฒฐํ•ฉ์„ ํ•  ๋•Œ๋Š”
  • String str1 = "abc";
  • String str2 = "def";
  • str1 + str2; ๐Ÿ‘ˆ ๋”ํ•˜๊ธฐ ์—ฐ์‚ฐ(+)์„ ์ด์šฉํ•œ๋‹ค.
  • String๊ฐ์ฒด์™€ String๊ฐ์ฒด๋ฅผ ๋”ํ•˜๋Š”(+)ํ–‰์œ„๋Š” ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น๊ณผ ๋ฉ”๋ชจ๋ฆฌ ํ•ด์ œ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋ฉฐ ๋”ํ•˜๋Š” ์—ฐ์‚ฐ์ด ๋งŽ์•„์ง„๋‹ค๋ฉด ์„ฑ๋Šฅ์ ์œผ๋กœ ์ข‹์ง€ ์•Š๋‹ค.

๐Ÿ”น StringBuilder

โœ… memory์— ๊ฐ’์„ appendํ•˜๋Š” StringBuilder์™€ StringBuffer

โœ… ๊ทธ๋ž˜์„œ ์‹ค์ œ๋กœ StringBuilder๋Š” append()๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค

  • ๊ทธ๋ž˜์„œ ๋‚˜์˜จ ๊ฒƒ์ด StringBuilder์ด๋‹ค.
  • StringBuilder๋Š” String๊ณผ ๋ฌธ์ž์—ด์„ ๋”ํ•  ๋•Œ ์ƒˆ๋กœ์šด ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ๊ธฐ์กด์˜ ๋ฐ์ดํ„ฐ์— ๋”ํ•˜๋Š” ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์†๋„๋„ ๋น ๋ฅด๋ฉฐ ์ƒ๋Œ€์ ์œผ๋กœ ๋ถ€ํ•˜๊ฐ€ ์ ๋‹ค.
  • ๋”ฐ๋ผ์„œ ๊ธด ๋ฌธ์ž์—ด์„ ๋”ํ•˜๋Š” ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•  ๊ฒฝ์šฐ StringBuilder์‚ฌ์šฉ์„ ๊ถŒ์žฅํ•œ๋‹ค.
profile
๋ช‡ ๋ฒˆ์„ ๋„˜์–ด์ ธ๋„ ์•ž์œผ๋กœ ๊ณ„์† ๋‚˜์•„๊ฐ€์ž

0๊ฐœ์˜ ๋Œ“๊ธ€