Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在堆上创建一个字符串对象,我必须确保该对象不是在字符串池上创建的。
默认情况下,Java 不会将 String 对象放入字符串池中,相反,它们使您可以灵活地通过调用intern().
intern()
使用new运算符强制 String 类在堆空间中创建一个新的 String 对象。
new
另请注意,在 Java 7 中,字符串池已从堆的 permgen 区域重新定位到主堆区域。