Java #22: How to Compare Strings in Java (Case Wise Too)

————————————Full Source Code———————-
/Programmer:Akinwale Owi
//Company:Dagba Computers
//Program Purpose:Comparing Strings(Case wise too)

package dagba.samples;

* @author Akin
public class DagbaSamples {

* @param args the command line arguments

public static void main(String[] args)
//String Variables I’m comparing
String firstWord = “Dagba”;
String secondWord = “dagba”;

//Testing out the complete equality
if ((firstWord).equals(secondWord))//If they are equal
System.out.println(“They are the same”);

//Print if the Strings are different
System.out.println(“They are different”);

System.out.println(“—Below testing for equality excluding case—-“);

//Testing for Equality excluding the Case
if (firstWord.equalsIgnoreCase(secondWord))//print if they are equal
System.out.println(“These words are the same, excluding case”);
//If the words are not equal
System.out.println(“These words are very different”);

}//end of main

}//end of public Dagba Class

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s