6:27 am - Sunday October 22, 2017

Compare equality of two string Ignoring case boolean equalsIgnoreCase(String anotherString)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

                        This method compares two strings. If the strings are equal output is true, else false. But this function is not case sensitive.

Example Program


public class Booleqin {

	public static void main(String[] args)

	{

		String s1 = "BOOLEAN FUNCTIONS";

		String s2 = "STRING handling functions";

		String s3 = "boolean functions";

		boolean b = s1.equalsIgnoreCase(s2);

		boolean b1 = s2.equalsIgnoreCase(s3);

		boolean b2 = s3.equalsIgnoreCase(s1);

		boolean b3 = s3.equalsIgnoreCase(null);

		System.out.println(b);

		System.out.println(b1);

		System.out.println(b2);

		System.out.println(b3);

	}

}

Output:

   false

   false

   true

   false

Description

             In this program, it compares string values. It is not-case sensitive. It compares two string values(s1&s2, s2&s3, s3&s1). Heres1string value is in upper case format and s3 value is in lower case format. Though the both strings have the same value it returns the output as true.

Filed in: Java Examples

Comments are closed.