- public class StringTest1 {
- public static void main(String[] args){
-
- StringBuilder s1 = new StringBuilder("hello");
- StringBuilder s2 = new StringBuilder("world");
- method_1(s1,s2);
- System.out.println(s1+"---"+s2);
- }
-
- public static void method_1(StringBuilder s1, StringBuilder s2){
- s1.append(s2);
- s1 = s2;
- System.out.println(s1);
- System.out.println(s2);
- }
- }
复制代码
输出:- world
- world
- helloworld---world
复制代码
为什么s1已经被s2赋值为world了 在main函数打印的时候还是helloworld?? |