+ 2
Explain how it's output is falsefalsefalsetrue
class String1 { public static void main(String[] arg) { StringBuffer sb1 = new StringBuffer("Hello"); StringBuffer sb2 = new StringBuffer("Hello"); String s1 = new String("Hello"); String s2 = new String("Hello"); System.out.print(sb1.equals(sb2)); System.out.print(s1 == s2); System.out.print(sb1 == sb2); System.out.print(s1.equals(s2)); } }
2 Réponses
+ 3
Check this code to understand
https://code.sololearn.com/cZms6c3vg2w3/?ref=app
+ 1
Here comes the explanation.
https://www.geeksforgeeks.org/difference-between-and-equals-method-in-java/