Java String compareToIgnoreCase() method with example

Java String compareToIgnoreCase() method compares two strings lexicographically, ignoring case differences. This method returns an integer whose sign is that of calling compareTo with normalized versions of the strings where case differences have been eliminated by calling Character.toLowerCase(Character.toUpperCase(character)) on each character.

Note that this method does not take locale into account, and will result in an unsatisfactory ordering for certain locales. The java.text package provides collators to allow locale-sensitive ordering.

Method Signature

public int compareToIgnoreCase(String str)


str – the String to be compared.


a negative integer, zero, or a positive integer as the specified String is greater than, equal to, or less than this String, ignoring case considerations.


1.2. See, String)

String compareToIgnoreCase() method Implementation

public int compareToIgnoreCase(String str) {
        return, str);

Java String compareToIgnoreCase() method example


public class CompareToIgnoreCaseExample {

	public static void main(String[] args) {

		String s1="ehowtonow";  
		String s2="eHowToNow";
		String s3="";
		String s4 = new String("EHOWTONOW");




Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. How to Split the String in Java
  2. Java String copyValueOf(char[] data, int offset, int count) method with example
  3. Java String indexOf(int ch, int fromIndex) method with example
  4. How to get Character unicode point in a String
  5. Java String compareTo() method with example
  6. Java String codePointBefore() method with example
  7. How to search a word inside String
  8. How to convert a String to Lower case
  9. Java String compareToIgnoreCase() method with example
  10. Java String concat() method with example
  11. Java String charAt() method with example
  12. Remove the particular character from string
  13. How to format the String by using Locale
  14. Java String Compare
  15. How to convert a String to Upper case

Be the first to comment

Leave a Reply