Willkommen

Übung Prog 2

8.11.23

Was machen wir heute

  • Generelle Fragen
  • Collections
    • Lists
    • Sets
    • Maps
  • Übung

Collections

Lists

List<String> arrayList = new ArrayList();

List<String> linkedList = new LinkedList();

arrayList.addAll(List.of("Blub", "Blubber", "Blubs"));

linkedList.addAll(List.of("Blub", "Blubber", "Blubs"));


System.out.println(arrayList.get(0));  

for(String s : linkedList){
  System.out.println(s);
}

arrayList.remove("Blubber");

arrayList.get(2);

SameButDifferentMeme

Collections

Sets

Set<String> hashSet = new HashSet();
Set<String> treeSet = new TreeSet();
hashSet.addAll(List.of("Blub","Blab","Blub","Aachen","BLUB" ));
for(String s : hashSet){
  System.out.println(s);
}
treeSet=hashSet;
for(String s : treeSet){
  System.out.println(s);
}

Collections

Sets

Output from slide before

Blab
Blub
BLUB
Aachen
TreeSet
Blab
Blub
BLUB
Aachen

Collections ?

Maps

Map<Integer, String> hashMap = new HashMap();
Map<Integer, String> treeMap = new TreeMap();

hashMap.put(1,"Something");
System.out.println(hashMap.get(1));