Java Collections Framework
Introduction to Collections
• Group of objects stored as single entity
• Provides better data manipulation than arrays
Collection Interfaces
• List: Ordered, allows duplicates
• Set: No duplicates
• Queue: FIFO principle
• Map: Key-value pairs
ArrayList
• ArrayList<String> list = new ArrayList<>();
• [Link]("Java"); [Link]("Python");
LinkedList
• Faster insertions/deletions than ArrayList
• LinkedList<Integer> ll = new LinkedList<>();
HashSet
• No duplicates, unordered
• HashSet<String> set = new HashSet<>();
HashMap
• Key-value storage
• HashMap<Integer, String> map = new
HashMap<>(); [Link](1, "Java");
Iterators
• Traverse collections
• for(String s : list) { [Link](s); }
Collections Utility Class
• sort(), reverse(), shuffle()
Summary
• Collections simplify storage and operations on
groups of objects