if (comparison < 0 ) {
// result is less
}
else if (comparison > 0) {
// result is greater
}
else {
System.out.println(something);
}
Hi there, quick question regarding the proper protocol with 'If' statements. The code above is sort of pseudo-code for what I'm writing.
Basically it compares two strings, if the strings are equal to each other, I want it to keep that information (system.out.println for now, but output written later).
This leaves me with an 'if' and an 'else if' that are of basically no use because I only want exact matches really.
What should be put between the {} of the 'if' and 'else if' (assuming there is a proper way to do this) or is there a better way to code this idea?
Thank you :)
Use String.equals, like this:
if (string1.equals(string2)) { System.out.println("Match!"); }
This gives you no superfluous if-statements.
Read more on the String class API.