PriorityQueue equals(Object) in Java

equals(Object): This method is available in java.util.PriorityQueue class of Java.

Syntax:

boolean java.lang.Object.equals(Object obj)

This method takes one argument. This method indicates whether some other object is "equal to" this one.

Parameters: One parameter is required for this method.

obj: the reference object with which to compare.

Returns: true if this object is the same as the obj argument; false otherwise.

Exceptions: NA

Approach

Java

import java.util.PriorityQueue;

public class PriorityQueueequals {
    public static void main(String[] args) {

        PriorityQueue<Integer> priorityQueue =
new PriorityQueue<Integer>();

        priorityQueue.add(12);
        priorityQueue.add(5);
        priorityQueue.add(10);
        priorityQueue.add(2);

        System.out.println(priorityQueue.equals(priorityQueue));

    }
}

Output:

true


No comments:

Post a Comment