I have a method that takes any iterable object type with unknown type T, and loops through it taking the items out of it and putting it into another data structure. I need to delete each item from the old iterable object as I go so I can re-add the items to it in sorted order.
I tried using .clear() on the object after looping, but it's not guaranteed to have a clear method. So how can I delete items as I go through it, or maybe make a new object with the same exact type but no values so I can re-add everything to it, only knowing that the object is Iterable?
public class PriorityQueue<K extends Comparable<? super K>,V> {
  public static <K> void PriorityQueueSort(Iterable<? extends K> list,
        PriorityQueue<? super K, ?> queue) {
      for (K item : list) {
          queue.insert(item, null);
      }
      list.clear();
  }
}
 
     
     
    