Collections: shuffle(List < ? > list,Random rnd)
/**
*Output:
List sorted in reverse: 20 8 -8 -20
List shuffled: 20 -20 -8 8
Minimum: -20
Maximum: 20
*/
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
public class MainClass {
public static void main(String args[]) {
LinkedList<Integer> ll = new LinkedList<Integer>();
ll.add(-8);
ll.add(20);
ll.add(-20);
ll.add(8);
Comparator<Integer> r = Collections.reverseOrder();
Collections.sort(ll, r);
System.out.print("List sorted in reverse: ");
for(int i : ll){
System.out.print(i+ " ");
}
System.out.println();
Collections.shuffle(ll);
System.out.print("List shuffled: ");
for(int i : ll)
System.out.print(i + " ");
System.out.println();
System.out.println("Minimum: " + Collections.min(ll));
System.out.println("Maximum: " + Collections.max(ll));
}
}
Related examples in the same category
1. | Collections.EMPTY_LIST | | |
2. | Collections.EMPTY_MAP | | |
3. | Collections.EMPTY_SET | | |
4. | Collections: binarySearch(List list, T key) | | |
5. | Collections: comparator() | | |
6. | Collections: copy(List dest, List src) | | |
7. | Collections: emptyList() | | |
8. | Collections: emptyMap() | | |
9. | Collections: emptySet() | | |
10. | Collections: enumeration(Collection c) | | |
11. | Collections: fill(List super T> list, R obj) | | |
12. | Collections: list(Enumeration e) | | |
13. | Collections: max(Collection < ? extends T > coll) | | |
14. | Collections: min(Collection < ? extends T > coll) | | |
15. | Collections: nCopies(int n, Object o) | | |
16. | Collections: reverse(List> list) | | |
17. | Collections: reverseOrder() | | |
18. | Collections: replaceAll(List list, T oldVal, T newVal) | | |
19. | Collections: rotate(List> list, int distance) | | |
20. | Collections: singleton(T o) | | |
21. | Collections: singletonList(T o) | | |
22. | Collections: singletonMap(T key, R value) | | |
23. | Collections: sort(List list) | | |
24. | Collections: sort(List < T > list, Comparator < ? super T > c) | | |
25. | Collections: swap(List> list, int i, int j) | | |
26. | Collections: synchronizedCollection(Collection c) | | |
27. | Collections: synchronizedList(List list) | | |
28. | Collections: synchronizedMap(Map m) | | |
29. | Collections: synchronizedSet(Set s) | | |
30. | Collections: synchronizedSet(SortedSet s) | | |
31. | Collections: synchronizedSortedMap(SortedMap m) | | |
32. | Collections: unmodifiableCollection(Collection> c) | | |
33. | Collections: unmodifiableList(List extends T> list) | | |
34. | Collections: unmodifiableMap(Map m) | | |
35. | Collections: unmodifiableSet(Set s) | | |