Pages

Compare String ignore capital or ordinary letters

Complete source code below will show you, how to compare two string with same characteristic but ignore about capital or ordinary letters. The characteristic that i mean here is, number of characters and sequence of characters. We will use method equalsIgnoreCase().

****************************************************************************
COMPLETE SOURCE CODE FOR : CompareStringIgnoreCapitalOrOrdinaryLetters.java
****************************************************************************


public class CompareStringIgnoreCapitalOrOrdinaryLetters
{
public static void main(String[]args)
{
//Create first String = aaAAA
//You can try other string that you want by change aaAAA
String firstString="aaAAA";

//Create second String = AAaaa
//You can try other string that you want by change AAaaa
String secondString="AAaaa";

//Check if first String is same or not to second String
if(firstString.equalsIgnoreCase(secondString))
{
//If first String equal to second String, it will print ( firstString is same to secondString )
System.out.println("firstString is same to secondString");
}
else
{
//If first String not equal to second String, it will print ( firstString is not same to secondString )
System.out.println("firstString is not same to secondString");
}
}
}


****************************************************************************
JUST COMPILE AND EXECUTE IT
****************************************************************************
Related Posts Plugin for WordPress, Blogger...