Pages

Compare String in java

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

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


public class CompareString
{
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.equals(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...