【发布时间】:2016-03-10 11:41:02
【问题描述】:
因为,在 Java 中,字符串被实现为 Object 类型的引用。此外,字符串 constants 被实现为对象。
例如:
System.out.println("This is a String");
在上面的语句中,“This is a String”也被实现为Object类型。这意味着它将被分配与
相同的内存String str = "This is a String";
我的问题是,如果我在同一个 System.out 语句中使用 + 运算符打印多个字符串会怎样,
System.out.println("This is a String" + "This is another String");
现在,我基本上要问的是,我想知道"This is a String" 和"This is another String" 是否会占用不同的内存空间或相同的内存空间??
另外,在println() 语句中的字符串之间添加一个变量会产生影响吗?
例如:
int i = 10;
System.out.println("This is a String" + i + "This is another String");
本站其他与字符串相关的问题没有具体回答我的问题,请多多指教^_^
任何帮助将不胜感激
【问题讨论】:
标签: java string memory memory-management string-concatenation