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.
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 ...
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.
Results that may be inaccessible to you are currently showing.
Hide inaccessible results