by @saigowthamr

How to compare the two strings in Java

Home » java » How to compare the two strings in Java

In Java, we can compare the two strings by using a double equals (==) operator.

Here is an example, which compares the first string with the second string.

String first =  "code";
String  second = "code";

System.out.println(first == second); // true

Similar, you can also use the equals() method to compare two strings in java.

String first =  "code";
String  second = "code";

System.out.println(first.equals(second)); // true