Using equals() to compare strings
It was told in a previous post that when comparing two strings to use the equals()
So rather than doing something like this
package relationships;
publicclass Starter{
publicstaticvoid main(String[] args){
String foo ="foo";
String bar ="bar";
if(foo == bar){
System.out.println("Strings are logically equal");
}elseif(foo != bar){
System.out.println("Strings are not logically equal");
}
}
}
Where the console would output "Strings are not logically equal" How would I do this using the equals() (other then using else)
package relationships;
publicclass Starter{
publicstaticvoid main(String[] args){
String foo ="foo";
String bar ="bar";
if(foo.equals(bar)){
System.out.println("Strings are logically equal");
}elseif(/* WHAT GOES HERE? */ ){
System.out.println("Strings are not logically equal");
}
}
}
I know to test if they are equal just to go like this foo.equals(bar) but what would I put in the else if?
else if( /* WHAT GOES HERE? */ )

