Collections manage groups of objects Provide far more functionality than basic arrays Distinct characteristics
Deletion insertion dynamic allocation size variability support for polymorphism
List
Stores objects while maintaining index and order allowing duplicates
ArrayList Possesses array characteristics with dynamic resizing Slower in terms of speed due to indexing (e.g., values inserted or deleted in the middle)
LinkedList Provides faster manipulation compared to ArrayList
Using Generics group specific types together List arr = new ArrayList<>();
Common Methods
arr.add(“Value”) : Adds an object
arr.get(index) : Accesses by index
arr.size() : Returns the size
arr.set(index, “Value”) : Modifies an index
arr.contains(“Value”) : Checks existence
arr.clear() : Clears all elements
arr.isEmpty() : Checks if empty
Collections Utility Class
Collections.addAll(list, val1, val2, …) : Adds multiple objects at once
Collections.frequency(list, val) : Counts occurrences
Collections.min(list) / Collections.max(list) : Finds min/max values
Collections.sort(list) : Sorts the list
Collections.shuffle(list) : Randomizes order
Collections.fill(list, val) : Initializes with a value
Set
Implements set theory does not allow duplicates
Hash
An algorithm that generates unpredictable values for a given input Sorting is impossible due to unpredictable nature of generated values Nearly impossible to retrieve the original value from the hash A one-way algorithm Offers fast performance and high security
LinkedList Usage
Stack (LIFO: Last In First Out) push pop peek
Queue (FIFO: First In First Out) offer poll peek