How to Compare Two Strings in Java

In this post, we will see how to compare two String in java.
As you might know, String implements Comparable interface, you can use compareTo method to compare two String in java.

Output:

Enter First String : Java
Enter Second String : Blog
First String is Greater than Second String.

That’s all about How to compare two Strings in java.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *