Important

Funktionen gcc-Compiler
Java Map, Queue, List, Tree → Collections, hauptsächlich Funktionen zum Hinzufügen/Entfernen
stream()
Predicate, Comparator
Sorting algorithms
C Basics
| Collection Type | Implementation | Ordered | Sorted | Allows Duplicates | Null Keys | Null Values |
Set | ==HashSet== | No | No | No | N/A | Yes |
Set | ==LinkedHashSet== | Yes | No | No | N/A | Yes |
Set | ==TreeSet== | No | Yes | No | N/A | No |
Map | ==HashMap== | No | No | No (keys) | Yes | Yes |
Map | ==LinkedHashMap== | Yes | No | No (keys) | Yes | Yes |
Map | ==TreeMap== | No | Yes | No (keys) | No | Yes |
Map | Hashtable | No | No | No (keys) | No | No |
Map | ConcurrentHashMap | No | No | No (keys) | No | Yes |
List | ==ArrayList== | Yes | No | Yes | N/A | Yes |
List | ==LinkedList== | Yes | No | Yes | N/A | Yes |
List | Vector | Yes | No | Yes | N/A | Yes |
List | Stack | Yes | No | Yes | N/A | Yes |
Explanation:
-
Ordered: Maintains the order of elements as they are inserted.
-
Sorted: Maintains elements in a sorted order based on natural ordering or a specified comparator.
-
Allows Duplicates: Whether the collection allows duplicate elements (for
SetandList) or duplicate keys (forMap). -
Null Keys: Whether the collection allows null keys (applicable to
Maponly). -
Null Values: Whether the collection allows null values.
Notes:
-
HashSetandHashMapdo not maintain any specific order. -
LinkedHashSetandLinkedHashMapmaintain the insertion order. -
TreeSetandTreeMapmaintain elements in a sorted order. -
HashtableandConcurrentHashMapdo not allow null keys or values. -
TreeSetdoes not allow null elements, andTreeMapdoes not allow null keys but allows null values. -
ArrayList,LinkedList,Vector, andStackmaintain the insertion order and allow duplicates and null values.
Generics
-
allows writing flexible,
-
type-safe code
-
reusable code
-
allow types to be parameters when defining classes, interfaces and methods.
Easy Example :
package generics;
public class Box<T>{
/**
*
* Here, Box can store any type T.
*/
private T item ;
public void setItem(T item ){
this.item = item;
}
public <T> void printItem(T item) {
System.out.println(item);
}
}- Here, printItem( T item ) is a generic method, that means that it is not bound to any type.
we can L
! Collections
Keep in mind :
-
when deleting elements while iterating over a Collections it cna get messed up
- thats why a safe removal is important