Java Quiz 2
Yes, it’s Java quiz time again!
“Everyone” knows you shouldn’t compare strings by reference equality (==), but can you explain why…
public class Test1 {
public static void main(String args[]) {
System.out.println((”use” == “use”) ? “True” : “False”);
}
}
…always prints ‘True’, and then…
public class Test2 {
public static void main(String args[]) {
System.out.println((new String(”mention”) == new String(”mention”)) ? “True” : “False”);
}
}
…always prints ‘False’?
About this entry
You are currently reading “Java Quiz 2”, an entry on Lamby's blog.
- Published:
- 27.12.07 / 1am
- Filed under:
- Computer, Planet ALUG, Planet UWCS, Planet WUGLUG

8 Comments
Jump to comment form | comments rss | trackback uri