Home Java Beginners Character Cases Ignoring case sensitiveness in java



Character Cases Ignoring case sensitiveness in java
Posted on: June 11, 2007 at 12:00 AM
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.*;

public class CharCompIgnoreCase{
  public static void main(String[] args) {
  System.out.println("Character comparation to ignore case example!");
  String str1 = "Vinod";
  String str2 = "Vinod";
  String str3 = "vinod";
  CharComp(str1, str2, str3);
  }
  public static void CharComp(String str1, String str2, String str3){
  System.out.println("String1 = " + str1);
  System.out.println("String2 = " + str2);
  System.out.println("String2 = " + str3);
  if(str1.compareToIgnoreCase(str2== 0){
  System.out.println("String1 and String2 are equal!");
  }
  else{
  System.out.println("String1 and String2 are not equal!");
  }
  if(str1.compareToIgnoreCase(str3== 0){
  System.out.println("String1 and String3 are equal!");
  }
  else{
  System.out.println("String1 and String3 are not equal!");
  }
  if(str2.compareToIgnoreCase(str3== 0){
  System.out.println("String2 and String3 are equal!");
  }
  else{
  System.out.println("String2 and String3 are not equal!");
  }
  }
}

Download this example.

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!

Related Tags for Character Cases Ignoring case sensitiveness in java:
cstringcomstringsintegermethodtypecomparevaluereturnintthiscasecaslikeignoretoposeitzerolipeinnonegativeasmntpartrososicaosioscomparetoesasepositivemesurnatkisivandarstrvatwzssriringthstatialugagatndomonor


More Tutorials from this section

Ask Questions?    Discuss: Character Cases Ignoring case sensitiveness in java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.