Home > Java > javaTutorial > body text

compareToIgnoreCase() compares two strings without case sensitivity

Y2J
Release: 2017-05-17 10:46:49
Original
2676 people have browsed it

The compareToIgnoreCase method compares two strings in lexicographic order, regardless of case. This method returns an integer.

Syntax

<span style="font-size: 14px;">public int compareToIgnoreCase(String str) <br/></span>
Copy after login

Return value: Depending on whether the specified String is greater than, equal to or less than this String (regardless of case), a negative value is returned respectively. Integer, 0, or a positive integer.

Parameters: str is the String specified for comparison.

Example This example uses the compareToIgnoreCase method to compare the strings strCom and strCom1 in lexicographic order, and assigns the result to the int variable strLower. Although one of the compared strings is lowercase and the other is uppercase, the return value of the string strLower is 0.

<span style="font-size: 14px;">String strCom = "I LIKE JAVA";   //定义一个字符串<br/>String strCom1 = "i like java";  //定义一个字符串<br/>int strLower = strCom.compareToIgnoreCase(strCom1);<br/>System.out.<span style="font-size: 16px;"><a href="http://www.php.cn/wiki/1362.html" target="_blank">print</a>ln(strLower);</span></span>
Copy after login

【Related recommendations】

1. Special recommendation"php Programmer Toolbox" V0.1 version download

2. Java Free video tutorial

3. Detailed introduction to compareToIgnoreCase() method

4. Java classic String comparison method: compareToIgnoreCase()

5. In-depth understanding of the differences between compareTo and comparetoIgnorecase

6. Detailed explanation of compareToIgnoreCase The principle of return value

The above is the detailed content of compareToIgnoreCase() compares two strings without case sensitivity. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template