Home >Java >JavaBase >Java case insensitive comparison

Java case insensitive comparison

angryTom
angryTomOriginal
2019-11-13 14:47:0211547browse

Java case insensitive comparison

Java case-insensitive comparison

1. Java has provided a built-in case judgment Method: equalsIgnoreCase().

Usage: (Recommended tutorial: java tutorial)

"ABC".equalsIgnoreCase("abc"); // 将字符串ABC与abc忽略大小写进行比较

2. Use toLowerCase() Compare with contains

Convert both strings to lowercase for comparison

s1.toLowerCase().contains(s2.toLowerCase());

Extension:

equalsIgnoreCase and The difference between equals

String.equals() is case-sensitive, while String.equalsIgnoreCase() ignores case

For example:

"ABC".equals ("abc") is false

"ABC".equalsIgnoreCase("abc") is true

The above is the detailed content of Java case insensitive comparison. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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