讲一下 讲下这个题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我的理解:String s1=“hello”在栈中新增s1引用,此时堆中没有“hello”,所以在堆中新增字符串“hello”;String s2=s1.subString(2,3)在栈中新增s2引用,同时算出subString(2,3)为“l”,此时堆中没有“l”,所以在堆中新增字符串“l”;String s3=s1.toString()在栈中新增s3引用,同时算出s1.toString()为“hello”,此时堆中含有字符串“hello”,所以在堆中新增字符串“hello”;String s4=new StringBuffer(s1).toString()在栈中新增s4引用,StringBuffer(s1).toString()为“hello”,因为采用了new的方式,因此在堆中新增了字符串“hello”; 我的理解:String s1=“hello”在栈中新增s1引用,此时堆中没有“hello”,所以在堆中新增字符串“hello”;String s2=s1.subString(2,3)在栈中新增s2引用,同时算出subString(2,3)为“l”,此时堆中没有“l”,所以在堆中新增字符串“l”;String s3=s1.toString()在栈中新增s3引用,同时算出s1.toString()为“hello”,此时堆中含有字符串“hello”,所以直接指向对中的字符串“hello”;String s4=new StringBuffer(s1).toString()在栈中新增s4引用,StringBuffer(s1).toString()为“hello”,因为采用了new的方式,因此在堆中新增了字符串“hello”; 第一行一个。第二行的substring方法,你查看源码会发现,它会产生一个新的String对象。第三行,String类的toString方法返回它本身,所以不产生新对象。第四行,new StringBuffer(s1)是不产生新的String对象的,但是StringBuffer的toString方法会产生一个新的String对象,可参看源码。所以,会产生三个String对象。 http://www.blogjava.net/mirenxiaoxiao/archive/2010/10/18/335457.html 双色球算法——有问题 java.io.IOException: No such file or directory 线程的面试题 D3出错了!为什么不能识别getParamenter(" ")啊 求一个Select语句:如何实现MySQl的递归查询 java+access2003数据库一些语句看不明白,请指教 我是菜鸟,向各位大侠请教个关于java中关于输入输出流的问题 请教JAVA 的编程问题? 还是原来那个流的问题,Up一样有分 数组作参数,这么传到方法里对么? 遇到一个问题,字符串引用打印的问题 求助一个关于java比较两个类的语句问题
String s1=“hello”
在栈中新增s1引用,此时堆中没有“hello”,所以在堆中新增字符串“hello”;
String s2=s1.subString(2,3)
在栈中新增s2引用,同时算出subString(2,3)为“l”,此时堆中没有“l”,所以在堆中新增字符串“l”;
String s3=s1.toString()
在栈中新增s3引用,同时算出s1.toString()为“hello”,此时堆中含有字符串“hello”,所以在堆中新增字符串“hello”;
String s4=new StringBuffer(s1).toString()
在栈中新增s4引用,StringBuffer(s1).toString()为“hello”,因为采用了new的方式,因此在堆中新增了字符串“hello”;
String s1=“hello”
在栈中新增s1引用,此时堆中没有“hello”,所以在堆中新增字符串“hello”;
String s2=s1.subString(2,3)
在栈中新增s2引用,同时算出subString(2,3)为“l”,此时堆中没有“l”,所以在堆中新增字符串“l”;
String s3=s1.toString()
在栈中新增s3引用,同时算出s1.toString()为“hello”,此时堆中含有字符串“hello”,所以直接指向对中的字符串“hello”;
String s4=new StringBuffer(s1).toString()
在栈中新增s4引用,StringBuffer(s1).toString()为“hello”,因为采用了new的方式,因此在堆中新增了字符串“hello”;