Sobes.tech
Intern — Senior

Differences between the == operator and the equals() method when comparing strings in Java

livecode

Task condition

This example demonstrates how the == operator and the equals() method work when checking string equality in Java.

String first = "123";
String second = "123";
String third = new String("123");

System.out.println(first == second);
System.out.println(first == third);
System.out.println(first.equals(second));
System.out.println(first.equals(third));