Javada memory nin nasıl çalıştığına dair fikir uyandıracak bir alıntıdır.

String s4 = new String ("restful"),
String s5 = new String ("restful"),
String s6 = new String ("peaceful"),
String s7 = s4,
String s8 = "restful",
String s9 = "restful";

bny.PNG

System.out.println (s4.equals (s5)); // the output is "true"

System.out.println (s4.equals (s6)); // the output is "false"

System.out.println (s4 == s5); // the output is "false"

System.out.println (s4 == s7); // the output is "true"

System.out.println (s4 == s8); // the output is "false"

System.out.println (s8 == s9); // the output is "true"

Buradan anlamaktayız ki equals metodu ile 2 eşittir farklı çalışmaktadır.

Equals  —-> Sahip olduğu veri tipi ve değerin eşitliğini kontrol ederken

Çift Eşittir —-> Memory’daki yerlerini kontrol eder.

Data Structures and the Java Collections Framework – book