Most new Java developers quickly learn that they should generally compare Java Strings using String.equals(Object) rather than using ==. This is emphasized and reinforced to new developers repeatedly ...
Q1: What is the difference between == and .equals() in Java? Answer: == checks if two references point to the same object in memory. .equals() checks if two objects have the same content or value.
If you are fortunate enough to be using JDK 7, the newly available Objects class is the obvious (at least to me) choice for implementing the “common” Java object ...
System.out.println("s eq sobj1 "+s.equals(sobj1)); //content comparison System.out.println("sobj1 eq sobj2 "+sobj1.equals(sobj2)); System.out.println("sobj1 eq sobj3 ...
It's not terribly clean, but you could use indexOf() and check if it returns -1. Better than breaking out a loop.