本帖最后由 程玉习 于 2014-1-7 09:08 编辑
- class Test
- {
- public static void method_2(StringBuilder sb1,StringBuilder sb2)
- {
- sb1.append(sb2);
- sb1 = sb2;
- sop(sb1.equals(sb2));//true
- }
- public static void method_1(String s1,String s2)
- {
- s1.replace('a','k');
- s1.replace('a','k');
- s1 = s2;
- sop(s1.equals(s2));//true
- }
- public static void sop(Object obj)
- {
- System.out.println(obj);
- }
- public static void main(String[] args)
- {
- String s1 = "java";
- String s2 = "hello";
- method_1(s1,s2);
- sop(s1+"------"+s2);
- StringBuilder sb1 = new StringBuilder("java");
- StringBuilder sb2 = new StringBuilder("hello");
- method_2(sb1,sb2);
- sop(sb1+"------"+sb2);
- }
- }
复制代码 结果为什么是这样?java------hello
javahello------hello
|