How to compare strings correctly [JAVA Tip]
The main objective of this post is to explain the correct method of comparing the strings in Java. Can you answer the following quiz? * QUIZ: Guess output of the following code snippet: String osName = System.getProperty(“osName”); if (osName.equals(“Windows”)) { System.out.println(“You’re using Windows”); } For now, let write down your answer on paper. I will let you know the correct answer at the end of this post. Friends, why I want you to answer the quiz above? Well, it’s because I’m going to share a tip about Strings comparison today. * Why Strings comparison? It sounds very simple, but do you know that you have to compare Strings in every coding day of your entire life? Unless you die or you don’t coding any more, comparing Strings is your day-to-day chore, like you eat and drink. I want to tell you about the comparison of a String variable against a String constant as shown in the code snippet above: String osName = System.getProp...