import java.util.*; class Collection_Algos { public static void main(String args[]) { LinkedList list = new LinkedList(); list.add(new Integer(2)); list.add(new Integer(8)); list.add(new Integer(5)); list.add(new Integer(1)); Iterator i = list.iterator(); Collections.reverse(list); Collections.shuffle(list); while(i.hasNext()) System.out.print(i.next() + " "); } }
a) 2 8 5 1
b) 1 5 8 2
c) 1 2 5 8
d) Any random order
d
Explanation: shuffle – randomizes all the elements in a list.
Output:
$ javac Collection_Algos.java
$ java Collection_Algos
1 5 2 8