Java – String equals() Example, Strings equals() program

String objects and string characters can be compared by equals() method in java. equals() method returns value in boolean. If string objects are matched with each other in string, it will return true, otherwise false. Use of String equals() in java is shown below.

Example of String equals() in java, JSP

public class StringEqualsExample {

    public static void main(String[] args) {

        String string = "Comparing strings";

        String stringNew = "New string";

        boolean checkString= string.equals(stringNew);

        boolean checkEqualsString = string.equals("Comparing strings");

        System.out.println("Comparing string not Match :"+checkString);

        System.out.println("Comparing string Match :"+checkEqualsString);
    }
}

Check More equals Ignore Case method in java String equalsIgnoreCase()

Output

Comparing string not Match :false
Comparing string Match :true

Tags:

Bookmark  

 

Leave a Reply

Security Code:

 

  Random Post