Does it give you a bellyache?
Never mind, you can compare them like this-
System.out.println(gg1.compareTo(gg3));
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String gg1 = "goldengate"; | |
String gg2 = "goldengate"; //s2 is stored in a string pool. | |
String gg3 = new String("goldengate"); | |
System.out.println(gg1==gg2); //is true, because they share | |
//the same memory addr | |
System.out.println(gg1==gg3); //false, because of 'new' |
System.out.println(gg1.compareTo(gg3));
No comments:
Post a Comment