String str = "hello"; 与 String str = new String("hello"); 有什么区别?
2016-03-31 10:10
459 查看
String str1 = "hello"; 如果已经为hello字符串分配了内存,那么str1指向hello内存对象的地址;如果没有就创建。
String str2 = "hello";
String str3 = "hello";
str1,str2,str3 这三个变量都是指向"hello"的地址,"hello"为三个变量共享。
String str4 = new String("hello");根据"hello"这个String对象再次构造一个String对象,将新构造出来的String对象的引用赋给str4,内存中实际存在两个"hello"对象,且存放的地址不一样。
String str2 = "hello";
String str3 = "hello";
str1,str2,str3 这三个变量都是指向"hello"的地址,"hello"为三个变量共享。
String str4 = new String("hello");根据"hello"这个String对象再次构造一个String对象,将新构造出来的String对象的引用赋给str4,内存中实际存在两个"hello"对象,且存放的地址不一样。
相关文章推荐
- 小项目不用session的登录控制 web.xml配置
- 如果做好测试PM【转载】
- 关于深度学习向量初始化的简单想法
- HTML学习(四)——图像
- 求字符串中数字之和
- spring+Quartz+maven 简单的定时任务
- Qt 建立带有子项目的工程
- Eclipse 插件安装jetty
- 图像高斯模糊算法的原理及实现
- Android--BroadcastReceiver应用详解
- 数组选择排序法
- sdas
- ASP.NET MVC 使用 Petapoco 微型ORM框架+NpgSql驱动连接 PostgreSQL数据库
- maven混淆Java代码
- AutoFac实现WebAPI依赖注入(EF以及Mysql)
- 3月“.网络”域名总量十强:排名不变 万网降幅最大
- OpenCV系列【2】,一个简单定标并储存结果的程序
- pfctl使用
- Mina 断线重连 - 解决方案
- Linux中系统时间的修改