Home > Java > JavaBase > body text

Java case insensitive comparison

angryTom
Release: 2019-11-13 14:47:02
Original
11521 people have browsed it

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忽略大小写进行比较
Copy after login

2. Use toLowerCase() Compare with contains

Convert both strings to lowercase for comparison

s1.toLowerCase().contains(s2.toLowerCase());
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!