API

chap02_String

<aside> 📌 String 불변 클래스

</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));
		// 동일 주소값 출력

		//

	}
}