- /*
- * 看程序写结果:
- * String作为参数传递:
- * StringBuffer作为参数传递:
- *
- */
- public class Demo {
- public static void main(String[] args) {
- String str = "Hello";//str = 0x2233
- fun1(str);//fun1(0x2233);
- System.out.println("str = " + str);//Hello
-
- StringBuffer buf = new StringBuffer("Hello");//0x7788
- fun2(buf);//fun2(0x7788)
- System.out.println("buf = " + buf);//HelloWorld
-
- for(int i = 0 ; i < str.length() / 2 ; i++){
- char c1 = str.charAt(i);
- char c2 = str.charAt(str.length() - 1 - i);
- if(c1 != c2){
- System.out.println("不是对称串");
- }
- }
- }
-
- public static void fun1(String str){//str = 0x2233
- str = "World";//"World"被开辟新空间存储:str = 0x4455
- }
- public static void fun2(StringBuffer buf){//buf = 0x7788
- buf.append("World");//0x7788.append("World");
- }
- }
复制代码 |
|