- java.lang.StringBuffer可变的字符串
- String之间的连接是通过开辟一块新的内存 让后将它们拷贝进来
- StringBuffer则可以直接在后面追加
- 方法:
append(char c)
delete(int start, int end)
insert(int offset, char[] str)
package 字符串Buffer;
public class TestString {
public static void main(String[] args) { String s = "MMMMM"; StringBuffer sb = new StringBuffer(s); sb.append(‘.‘).append("NNNN"); System.out.println(sb); sb.delete(5,sb.length()); System.out.println(sb); sb.insert(0, ‘a‘); System.out.println(sb); sb.reverse(); System.out.println(sb); }
}
时间: 2024-11-05 16:01:35