请看程序就OK了:
- /*
- 有点小疑惑:不是说String一旦被定义初始化就不能被改变吗?
- 我这个小程序就有点矛盾哦,求详细介绍……
- */
- class TestString
- {
- public static void main(String[] args)
- {
- String s1="hello good luck to you!";
- String s2=s1.replace('e','w');
-
- System.out.println(s2);
- System.out.println(s1);
- /*
- 打印结果是:
- hwllo good luck to you!
- hello good luck to you!
- */
- /*
- String s1="hello good luck to you!";
- s1=s1.replace('e','w');
-
- System.out.println(s1);
- 打印结果是:hwllo good luck to you!
- 那原来的s1跑到哪里去呢?
- */
- }
- }
复制代码 |
|