Home » java » Java String Method compareToIgnoreCase()

Java String Method compareToIgnoreCase()

This method is used to compare two string with case ignorance and compare both string lexicographically. If both strings are same then it returns 0. If first string is greater then another then it returns positive integer, if second string is greater then first then it returns negative integer value.

Signature

public int compareToIgnoreCase(String str)

Parameters

str – String value that will compared with string.

Return

Integer value. if string is greater then passed str value then it returns positive integer if both strings are equal then it returns zero if passed str is greater then string then this method returns negative integer value.

Example1

Result

In above program comparing same string is returning 0. In second println() statement A is lexicographically smaller then b so it is returning -1. In third println() statement C is lexicographically greater then b so it is returning 1 and so on.

Example2

Result

Managed by MochaHost - Fast & Easy WordPress Hosting