문자열을 변경하거나 수정할 수 있는 클래스
<aside>
💡 A thread-safe, mutable sequence of characters. A string buffer is like a String
, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.
</aside>
쓰레드에서 안전한 가변적인 문자열 시퀀스, String과 비슷하지만 수정할 수 있습니다. 언제든지 특정 시점에는 특정 문자 시퀀스를 포함하고 있지만, 시퀀스의 길이와 내용은 특정한 메서드 호출을 통해 변경될 수 있습니다.
<aside> 💡 String buffers are safe for use by multiple threads. The methods are synchronized where necessary so that all the operations on any particular instance behave as if they occur in some serial order that is consistent with the order of the method calls made by each of the individual threads involved.
</aside>
String buffer
는 멀티스레드에 사용해도 안전합니다.
필요한 경우에는 메서드가 동기화되어 있으므로 모든 특정 인스턴스에 대한 모든 작업이 관련된 각 개별 스레드의 메서드 호출 순서와 일관된 시리얼 순서로 발생하는 것처럼 동작합니다.
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/StringBuffer.html
append 및 insert 메서드
**StringBuffer z = new StringBuffer(); // start
z.append("le"); // "startle"
z.insert(4, "le"); // "starlet"으로 변경**
**StringBuffer sb = new StringBuffer();
sb.append(x) = sb.insert(sb.length(),x);**