Test for equality with Objects.equals - Java Object Oriented Design

Java examples for Object Oriented Design:Objects Utility

Description

Test for equality with Objects.equals

Demo Code

import java.util.Objects;

public class Main {
  public static void main(String[] args) {
    // Test for equality
    boolean isEqual = Objects.equals(null, null);
    System.out.println("null is equal to null: " + isEqual);

    isEqual = Objects.equals(null, "XYZ");
    System.out.println("null is equal to XYZ: " + isEqual);

  }/*from w  w  w. ja  v  a 2  s .  c  om*/

}

Result


Related Tutorials