There is a method called String.intern which, essentially, takes all Strings that are the same and puts them into a hash table (I am sort of lying, but for this it is the concept that matters, not the reality).
String s1 = "BloodParrot is the man";
String s2 = "BloodParrot is the man";
String s3 = new String("BloodParrot is the man").intern();
System.out.println(s1.equals(s2));
System.out.println(s1 == s2);
System.out.println(s1 == s3);
System.out.println(s1.equals(s3));
should have them all being "true". This is because (and I am lying a bit here again, but it still only matters for the concept not reality) String s1 = "BloodParrot is the man"; is done something like String s1 = "BloodParrot is the man".intern();
No comments:
Post a Comment