Search code examples
javapriority-queue

How to insert long datatype in Priority Queue Java


I want to store all long type integer to a priority queue, and I want to intialize the queue something like this

PriorityQueue<long> pQueue = new PriorityQueue<>();

Is there an alternative available in java collections to achieve something like this?


Solution

  • Java doesn't allow primitive types in generics. You must use wrapper class like below.

    PriorityQueue<Long> pQueue = new PriorityQueue<>();