java - New String vs String s = "something" , what's the difference ? -


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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -