A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

public class Foo {
        public static void main(String[] args) {
                String strValue = "ABCDEFG";
                strValue.substring(3);
                strValue.concat("123");
                System.out.println(strValue);       
                String value = new String ("ABCDEFG");
                System.out.println(strValue == value);
        }
}

3 个回复

倒序浏览
strValue.substring(3);只是截取后三位,并没有修改 应写为strValue =strValue.substring(3);
下面的语句同理
回复 使用道具 举报
本帖最后由 棉/mg花/x糖 于 2013-5-25 22:25 编辑

楼主,你好,我来帮你解答:
strValue.substring(3);
strValue.concat("123");

操作完成后,得到的是一个新字符串,必须存储起来,这里并没有存储,也没存到strValue中。
因此相当于无用操作,即可以把这两行当成被注释了的语句。

故最后结果一定是false。

因为strValue是编译时就加载进内存的字符串,而value是在运行是才创建的字符串。
二者引用不一样。
回复 使用道具 举报
你没有接收处理过的字符串。strValue = strValue.substring(3);
strValue = strValue.concat("123");
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马