Java String.compareToIgnoreCase() method usage example tutorial, compare two strings, dictionaries, ignore case differences
Description
java.lang.String.compareToIgnoreCase() Method compares two strings, dictionaries, ignoring case differences.
Statement
The following is the declaration of the java.lang.String.compareToIgnoreCase() method
public int compareToIgnoreCase(String str)
Parameters
str -- This is the string to be compared.
Return value
This method returns a negative integer , zero or a positive integer if the specified string is greater than, equal to or less than this string, ignoring case considerations.
Exception
NA
##Example
The following example illustrates how to use the java.lang.String.compareToIgnoreCase() methodpackage com.yiibai; import java.lang.*; public class StringDemo { public static void main(String[] args) { String str1 = "tutorials", str2 = "TUTORIALS"; // comparing str1 and str2 with case ignored int retval = str1.compareToIgnoreCase(str2); // prints the return value of the comparison if (retval > 0) { System.out.println("str1 is greater than str2"); } else if (retval == 0) { System.out.println("str1 is equal to str2"); } else { System.out.println("str1 is less than str2"); } } }
str1 is equal to str2
Special recommendation: "php Programmer Toolbox" V0.1 version download
2. 3.compareToIgnoreCase() compares two strings without case sensitivity
4.Java Classic string comparison method: compareToIgnoreCase()
5.In-depth understanding of the differences between compareTo and comparetoIgnorecase
6.Detailed explanation The principle of return value of compareToIgnoreCase
The above is the detailed content of Detailed introduction to compareToIgnoreCase() method. For more information, please follow other related articles on the PHP Chinese website!