Tuesday, 21 April 2015

How to work Equals() and EqualsIgnoreCase() method in java

Equals():-To compare two strings for equality.
EqualsIgnoreCase():-The comparison is case-sensitive String if both are same return boolean value= true
=========Equals.java===============

/**
 *
 * @author Ananddw
 */
public class Equals {

    public static void main(String[] args) {

        String str1 = "Anand";
        String str2 = "anand";
        String str3 = "Ajeet";
        String str4 = "Antrish";

        // Calling equals method
        System.out.println("Compare str1 and str2 with equals method===>" + str1.equals(str2));
        System.out.println("Compare str1 and str3 with equals method===>" + str1.equals(str3));
        System.out.println("Compare str3 and str4 with equals method===>" + str3.equals(str4));
        //calling equals ignore method
       System.out.println("Compare str1 and str2 with equalsIgnore method===>" + str1.equalsIgnoreCase(str2));
        System.out.println("Compare str1 and str3 with equalsIgnore method===>" + str1.equalsIgnoreCase(str3));
        System.out.println("Compare str3 and str4 with equalsIgnore method===>" + str3.equalsIgnoreCase(str4));

    }

}

No comments:

Post a Comment

Map class field to map

 import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; public class AutogeneratedClassMapper {     public static M...