java - New String vs String s = "something" , what's the difference ? -
this question has answer here:
consider code :
public class strings { public static void createstr() { string s1 = new string("one"); string s2 = "one"; system.out.println(s1); system.out.println(s2); } public static void main(string args[]) { createstr(); } }
what's difference between string s1 = new string("one");
, string s2 = "one";
?
string s1 = new string("one"); // created on heap , not interned unless .intern() called explicityly. string s2 = "one"; // created in string pool , interned automatically compiler.
Comments
Post a Comment