May 25

Why StringBuffer and StringBuilder has not overridden equals() and hashCode()

Comparing Two Strings: If we want to compare two strings,we can simply use equals() as below String str1=new String("nataraz");     String str2=new String("nataraz");      System.out.println(str1.equals(str2));//prints true     System.out.println(str1==str2);//prints false     System.out.println(str1.hashCode()+":"+str2.hashCode());//returns same value hashCode() is overrided in String class,and … Continue reading