Die Klasse Collections hat viele statische Methoden um mit verschiedenen Datenstrukturen zu arbeiten.
Die Methoden verändern die übergebene Liste. Beispiele:
Collections.sort(zahlen); // eine Liste sortieren
var max = Collections.max(zahlen); // größter Wert einer Collection
System.out.println(max); // (var = Datenyp automatisch)
Collections.shuffle(zahlen); // eine Liste zufällig mischen
Collections.addAll(zahlen, 5, 6, 10); // mehrere Werte oder Array hinzufügen| Collection | Interface | Ordered | Sorted | Thread safe | Duplicate | Nullable |
|---|---|---|---|---|---|---|
| ArrayList | List | Y | N | N | Y | Y |
| Vector | List | Y | N | Y | Y | Y |
| LinkedList | List, Deque | Y | N | N | Y | Y |
| CopyOnWriteArrayList | List | Y | N | Y | Y | Y |
| HashSet | Set | N | N | N | N | One null |
| LinkedHashSet | Set | Y | N | N | N | One null |
| TreeSet | Set | Y | Y | N | N | N |
| CopyOnWriteArraySet | Set | Y | N | Y | N | One null |
| ConcurrentSkipListSet | Set | Y | Y | Y | N | N |
| HashMap | Map | N | N | N | N (key) | One null (key) |
| HashTable | Map | N | N | Y | N (key) | N (key) |
| LinkedHashMap | Map | Y | N | N | N (key) | One null (key) |
| TreeMap | Map | Y | Y | N | N (key) | N (key) |
| ConcurrentHashMap | Map | N | N | Y | N (key) | N |
| ConcurrentSkipListMap | Map | Y | Y | Y | N (key) | N |
| ArrayDeque | Deque | Y | N | N | Y | N |
| PriorityQueue | Queue | Y | N | N | Y | N |
| ConcurrentLinkedQueue | Queue | Y | N | Y | Y | N |
| ConcurrentLinkedDeque | Deque | Y | N | Y | Y | N |
| ArrayBlockingQueue | Queue | Y | N | Y | Y | N |
| LinkedBlockingDeque | Deque | Y | N | Y | Y | N |
| PriorityBlockingQueue | Queue | Y | N | Y | Y | N |