Junior — Middle
Milliseid kogumite tüüpe ja nende rakendusi olete Java-s andmete salvestamiseks kasutanud?
sobes.tech AI
Vastus AI-lt
In Java, I used various types of collections from the java.util package for storing and processing data:
- List (e.g., ArrayList, LinkedList) — ordered collections that allow duplicates. ArrayList is good for quick access by index, LinkedList for frequent insertions and deletions.
- Set (HashSet, TreeSet) — collections without duplicates. HashSet provides fast access, TreeSet keeps elements in sorted order.
- Map (HashMap, TreeMap) — collections of key-value pairs. HashMap provides quick access by key, TreeMap is sorted by keys.
Example of using ArrayList and HashMap:
List<String> list = new ArrayList<>();
list.add("apple");
list.add("banana");
Map<String, Integer> map = new HashMap<>();
map.put("apple", 3);
map.put("banana", 5);