String 和Stringbuffer有什么区别呢?
看下面的例子:
- public static void changeString(String input){
- input=input+"___";
- // System.out.println(input);
- }
- public static void changeStringBuffer(StringBuffer input){
- input.append("___");
- // System.out.println(input);
- }
- @Test
- public void test_String(){
- String input="whuang";
- System.out.println(input);
- changeString(input);
- System.out.println(input);
- }
运行结果是:
whuang
whuang
- @Test
- public void test_StringBuffer(){
- StringBuffer stringb=new StringBuffer("whuang");
- System.out.println(stringb);
- changeStringBuffer(stringb);
- System.out.println(stringb);
- }
运行结果是:
whuang
whuang___
时间: 2024-12-06 16:51:10