I want to add string and integer elements into a Priority Queue. However,after adding string elements and then integer, the program breaks and gives me error as following: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
Is it not allowed to have values of multiple types in a single PriorityQueue? What could be the other way around?
My PriorityQueue looks like this:
PriorityQueue queue = new PriorityQueue();
Element to add is as following:
public void addElementToQueue(Object obj) {
queue.add(obj);
}