Java equals() Vs ==
The String equals() method is used to compare two strings for equality. It compares the characters inside a string object.
The == operator compares the two object references.
Example:
public class Equalsto { public static void main(String args[]) { String s1=new String("Onlinetpoint"); String s2=new String("Onlinetpoint"); System.out.println(s1+ " equals "+s2+"-> "+s1.equals(s2)); System.out.println(s1+ " == "+s2+"-> " +(s1==s2)); } }
Quickly Find What You Are Looking For
Onlinetpoint is optimized for basic learning, practice and more. Examples are well checked and working examples available on this website but we can't give assurity for 100% correctness of all the content. This site under copyright content belongs to Onlinetpoint. You agree to have read and accepted our terms of use, cookie and privacy policy.