import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.PriorityQueue; public class CollectionExample { public static double avg(Collection collectionIn) { double total = 0; for (Integer val : collectionIn) { total += val; } return total / collectionIn.size(); } public static void main(String[] args) { ArrayList collectionOne = new ArrayList(); PriorityQueue collectionTwo = new PriorityQueue(); for (int i=10; i>=0; i--) { collectionOne.add(i); collectionTwo.add(i); } System.out.println("AL: " + collectionOne); System.out.println("PQ: " + collectionTwo); System.out.println("AL avg: " + avg(collectionOne)); System.out.println("PQ avg: " + avg(collectionTwo)); Collections.shuffle(collectionOne); //Collections.shuffle(collectionTwo); System.out.println("AL: " + collectionOne); System.out.print("PQ iterated: "); for (Integer val : collectionTwo) { System.out.print(val + " "); } System.out.println(); System.out.print("PQ removed: "); while (!collectionTwo.isEmpty()) { System.out.print(collectionTwo.remove() + " "); } System.out.println(); } } //Copyright 2016 Evan Golub