版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/thirtyfive16/article/details/53258591
String s3 = "hel" + new String("lo");底层到底是如何执行的呢?
写个程序,用eclipse做debug可以得到详细的执行的顺序
1 load StringBuilder类
2 生成临时变量StringBuilder,保存"hel"字符串
3 执行String(String)的构造函数,得到字符串"lo"
4 执行StringBuilder.append() 把"lo” append到“hel”上得到字符串“hello”
5 执行StringBuilder.toString() 返回"hello”给变量S3.
为什么这么执行呢?