0
0
Javaprogramming~15 mins

String comparison in Java - Practice Problems & Coding Challenges

Choose your learning style8 modes available
trophyChallenge - 5 Problems
🎖️
String Comparison Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 code output
intermediate
2:00remaining
Output of String equality check with == operator
What is the output of this Java code snippet?
Java
public class Main {
    public static void main(String[] args) {
        String a = "hello";
        String b = "hello";
        System.out.println(a == b);
    }
}
Atrue
Bfalse
CCompilation error
DRuntime exception
Attempts:
2 left
💻 code output
intermediate
2:00remaining
Output of String equality check with new operator
What is the output of this Java code snippet?
Java
public class Main {
    public static void main(String[] args) {
        String a = new String("hello");
        String b = new String("hello");
        System.out.println(a == b);
    }
}
Atrue
BRuntime exception
CCompilation error
Dfalse
Attempts:
2 left
💻 code output
advanced
2:00remaining
Output of equals() method for String comparison
What is the output of this Java code snippet?
Java
public class Main {
    public static void main(String[] args) {
        String a = new String("hello");
        String b = "hello";
        System.out.println(a.equals(b));
    }
}
Atrue
Bfalse
CCompilation error
DRuntime exception
Attempts:
2 left
💻 code output
advanced
2:00remaining
Output of compareTo() method for String comparison
What is the output of this Java code snippet?
Java
public class Main {
    public static void main(String[] args) {
        String a = "apple";
        String b = "banana";
        System.out.println(a.compareTo(b));
    }
}
A0
BNegative integer
CPositive integer
D-1
Attempts:
2 left
💻 code output
expert
2:00remaining
Output of String interning and == operator
What is the output of this Java code snippet?
Java
public class Main {
    public static void main(String[] args) {
        String a = new String("test");
        String b = a.intern();
        String c = "test";
        System.out.println(a == b);
        System.out.println(b == c);
    }
}
Afalse\nfalse
Btrue\ntrue
Cfalse\ntrue
Dtrue\nfalse
Attempts:
2 left