Sunday 21 April 2019

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

Consider the 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 the difference between String s1 = new String("one"); and String s2 = "one"; ?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...