In this section, you will learn how to compare two strings ignoring case sensitiveness Java provides the method that ignores cases, it only compare the character's sequence.
Character Cases Ignoring case sensitiveness in java
In this section, you will learn how to compare two strings ignoring case sensitiveness Java provides the method that ignores cases, it only compare the character's sequence. The compareToIgnoreCase() method compares two strings and ignores its cases. This method returns an integer type value like: a negative integer, a positive or zero.
Description of program:
The following program compares two strings and ignore these cases but it compares the sequence of characters in the given string. In this program, three string types data have been used that have to be compared. Here the CharComp() method is applied for comparing strings. The compareToIgnoreCase() method compares strings and shows the given message.
Description of code:
compareToIgnoreCase(String str):
This method is used to compare two strings with ignored cases. It takes
following arguments:
str: This is the string that have to be compared.
Here is the code of program:
import java.lang.*;
|
Output of program:
C:\vinod\Math_package>javac CharCompIgnoreCase.java C:\vinod\Math_package>java CharCompIgnoreCase Character comparation to ignore case example! String1 = Vinod String2 = Vinod String2 = vinod String1 and String2 are equal! String1 and String3 are equal! String2 and String3 are equal! |