Home > Back-end >  How to insert long datatype in Priority Queue Java
How to insert long datatype in Priority Queue Java

Time:05-23

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?

CodePudding user response:

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

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