Java – equals vs ==

String method equals check if both references points objects with same values stored in them. Operator == check if both references points to same object.

public class Main {
  public static void main(String[] args) {
    String str1 = "Hello";
    String str2 = new String("Hello");
    System.out.println(str1 == str2);
OpenJDK 64-Bit Server VM warning: Insufficient space for shared memory file:
Try using the option to select an alternate temp location.

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments