CJCoding With Joseph
15per day
← Back to Question List
Java Code Walkthrough #7

String Comparison Gotcha

hardClasses

📄 Code

Read carefully — what does this print?
1public class Main {
2 public static void main(String[] args) {
3 String s1 = new String("hello");
4 String s2 = new String("hello");
5 System.out.println(s1 == s2);
6 System.out.println(s1.equals(s2));
7 }
8}

🎯 Your Answer