Java UUID.equals(Object obj) method example

Java UUID.equals(Object obj) method example

By technicalkeeda, Views 402, Date 21-Feb-2018

In this tutorial, You will learn how to check if the two UUID's are equal or not. Java UUID.equals(Object obj) method returns true if the objects are the same.

tags Java

Compares this object to the specified object. The result is true if and only if the argument is not null, is a UUID object, has the same variant, and contains the same value, bit for bit, as this UUID.


public boolean equals(Object obj)


obj - The object to be compared.


true if the objects are the same; false otherwise.

Java UUID equals(Object obj) example

  • UUID.fromString("6224c18d-d004-11bd-984e-b8d80b2bdff8"); It creates a UUID from the string standard representation.
  • uuid1.equals(uuid2); It will compare uuid1 to uuid2. In this case it returns true, because both UUID are same.
  • uuid1.equals(uuid3); It will compare uuid1 to uuid3. In this case it returns false, because both UUID are different.
package com.technicalkeeda;

import java.util.UUID;

public class App {

    public static void main(String[] args) {

        UUID uuid1 = UUID.fromString("6224c18d-d004-11bd-984e-b8d80b2bdff8");
        UUID uuid2 = UUID.fromString("6224c18d-d004-11bd-984e-b8d80b2bdff8");
        UUID uuid3 = UUID.fromString("5289df73-7df5-3326-bcdd-22597afb1fac");

        System.out.println("Is uuid1 equal to uuid2 ? " + uuid1.equals(uuid2));
        System.out.println("Is uuid1 equal to uuid3 ? " + uuid1.equals(uuid3));


Is uuid1 equal to uuid2 ? true
Is uuid1 equal to uuid3 ? false

Suggested Posts



Hi there! I am founder of and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][]