B_StringMethodTest.java
C_StringTokenizerTest.java
D_StringBufferAndBuilder
<aside> 📌 String 불변 클래스
StringBuffer와 StringBuilder는 Mutable(변하는) 클래스
String 클래스는 문자열 연산이 빈번하게 일어나는 알고리즘에서 메모리 이슈가 발생,
그것을 해결하기 위해 StringBuilder와 StringBuffer 클래스가 나옴
StringBuilder와 StringBuffer은 기본적으로 동일한 메서드를 지닌다.
차이점은 '동기화' 유무
추후 배우게 될 'Thread'개념이 적용되어 있음
StringBuffer은 멀티스레드 환경에서 유용
StringBuilder은 단일 스레드 환경에서 유용
</aside>
package com.kh.chap02_string.controller;
public class D_StringBufferAndBuilder {
public void method() {
String str = "Hello";
str += "World";
StringBuffer sb = new StringBuffer("Hello");
System.out.println("변경 전 sb 주소값 : "+System.identityHashCode(sb));
sb.append("World");
System.out.println("변경 후 sb 주소값 : "+System.identityHashCode(sb));
// 동일 주소값 출력
StringBuilder sb2 = new StringBuilder("Hello");
System.out.println("변경 전 sb2 주소값 : "+System.identityHashCode(sb2));
sb2.append("World");
System.out.println("변경 후 sb2 주소값 : "+System.identityHashCode(sb2));
// 동일 주소값 출력
//
}
}