Skip to content

Latest commit

ย 

History

History
36 lines (24 loc) ยท 1.38 KB

[java] String StringBuilder StringBuffer ์ฐจ์ด.md

File metadata and controls

36 lines (24 loc) ยท 1.38 KB

String, StringBuffer, StringBuilder


๋ถ„๋ฅ˜ String StringBuffer StringBuilder
๋ณ€๊ฒฝ Immutable Mutable Mutable
๋™๊ธฐํ™” Synchronized ๊ฐ€๋Šฅ (Thread-safe) Synchronized ๋ถˆ๊ฐ€๋Šฅ.

1. String ํŠน์ง•

  • new ์—ฐ์‚ฐ์„ ํ†ตํ•ด ์ƒ์„ฑ๋œ ์ธ์Šคํ„ด์Šค์˜ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์€ ๋ณ€ํ•˜์ง€ ์•Š์Œ (Immutable)
  • Garbage Collector๋กœ ์ œ๊ฑฐ๋˜์–ด์•ผ ํ•จ.
  • ๋ฌธ์ž์—ด ์—ฐ์‚ฐ์‹œ ์ƒˆ๋กœ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“œ๋Š” Overhead ๋ฐœ์ƒ
  • ๊ฐ์ฒด๊ฐ€ ๋ถˆ๋ณ€ํ•˜๋ฏ€๋กœ, Multithread์—์„œ ๋™๊ธฐํ™”๋ฅผ ์‹ ๊ฒฝ ์“ธ ํ•„์š”๊ฐ€ ์—†์Œ. (์กฐํšŒ ์—ฐ์‚ฐ์— ๋งค์šฐ ํฐ ์žฅ์ )

String ํด๋ž˜์Šค : ๋ฌธ์ž์—ด ์—ฐ์‚ฐ์ด ์ ๊ณ , ์กฐํšŒ๊ฐ€ ๋งŽ์€ ๋ฉ€ํ‹ฐ์“ฐ๋ ˆ๋“œ ํ™˜๊ฒฝ์—์„œ ์ข‹์Œ


2. StringBuffer, StringBuilder ํŠน์ง•

  • ๊ณตํ†ต์ 
    • new ์—ฐ์‚ฐ์œผ๋กœ ํด๋ž˜์Šค๋ฅผ ํ•œ ๋ฒˆ๋งŒ ๋งŒ๋“ฌ (Mutable)
    • ๋ฌธ์ž์—ด ์—ฐ์‚ฐ์‹œ ์ƒˆ๋กœ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์ง€ ์•Š๊ณ , ํฌ๊ธฐ๋ฅผ ๋ณ€๊ฒฝ์‹œํ‚ด
    • StringBuffer์™€ StringBuilder ํด๋ž˜์Šค์˜ ๋ฉ”์„œ๋“œ๊ฐ€ ๋™์ผํ•จ.
  • ์ฐจ์ด์ 
    • StringBuffer๋Š” Thread-Safeํ•จ / StringBuilder๋Š” Thread-safeํ•˜์ง€ ์•Š์Œ (๋ถˆ๊ฐ€๋Šฅ)

StringBuffer ํด๋ž˜์Šค : ๋ฌธ์ž์—ด ์—ฐ์‚ฐ์ด ๋งŽ์€ Multi-Thread ํ™˜๊ฒฝ

StringBuilder ํด๋ž˜์Šค : ๋ฌธ์ž์—ด ์—ฐ์‚ฐ์ด ๋งŽ์€ Single-Thread ๋˜๋Š” Thread ์‹ ๊ฒฝ ์•ˆ์“ฐ๋Š” ํ™˜๊ฒฝ