Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8268765

java.lang.ClassCastException: java.lang.String while iterating Priority Queue

    XMLWordPrintable

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      package stlabs.collectionframework;

      import java.util.Iterator;
      import java.util.LinkedList;
      import java.util.PriorityQueue;
      import java.util.Queue;

      public class QueueProgram
      {
          public static void main(String[] args)
          {
              Queue<Object> queue=new PriorityQueue<>();
              queue.add("Ankit");
              queue.add("Sandip");
              queue.add("Pankaj");
              queue.add(10);
              queue.remove("Sandip");

              Iterator itr= queue.iterator();
              while(itr.hasNext())
              {
                  System.out.println(itr.next());
              }
          }
      }


      A DESCRIPTION OF THE PROBLEM :
      Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
      at java.lang.Integer.compareTo(Integer.java:52)
      at java.util.PriorityQueue.siftUpComparable(PriorityQueue.java:657)
      at java.util.PriorityQueue.siftUp(PriorityQueue.java:648)
      at java.util.PriorityQueue.offer(PriorityQueue.java:345)
      at java.util.PriorityQueue.add(PriorityQueue.java:322)
      at stlabs.collectionframework.QueueProgram.main(QueueProgram.java:16)


        Attachments

          Activity

            People

            Assignee:
            tongwan Andrew Wang
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: