Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

compareToIgnoreCase()

Example

Compare two strings while disregarding differences in case:

String myStr1 = "HELLO";
String myStr2 = "hello";
System.out.println(myStr1.compareToIgnoreCase(myStr2));

Definition and Usage

The compareToIgnoreCase() method compares two strings based on their order in the dictionary, disregarding differences in case.

The comparison relies on the Unicode value of each character within the string, which is converted to lowercase before comparison.

The method returns 0 when the strings are equal, disregarding case differences. If the string is less than the other string (fewer characters), it returns a value less than 0; if the string is greater than the other string (more characters), it returns a value greater than 0.

Syntax

public int compareToIgnoreCase(String string2)

Parameter Values

Parameter

Description

string2

A string that represents the comparison target.

Technical Details

Returns

An integer value: 0 signifies equality between the strings, disregarding case differences. If the string is lexicographically before the other string, it returns a value less than 0. If the string is lexicographically after the other string (contains more characters), it returns a value greater than 0.

Java version

1.2