0% found this document useful (0 votes)
3 views3 pages

Java_Collections_Framework_Notes

The document outlines the Java Collections Framework, detailing its hierarchy and various types such as List, Set, Queue, and Map. It provides examples and methods for each collection type, including ArrayList, HashSet, LinkedList, and HashMap. Additionally, it highlights differences between arrays and collections, as well as the characteristics of different Set and Map implementations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Java_Collections_Framework_Notes

The document outlines the Java Collections Framework, detailing its hierarchy and various types such as List, Set, Queue, and Map. It provides examples and methods for each collection type, including ArrayList, HashSet, LinkedList, and HashMap. Additionally, it highlights differences between arrays and collections, as well as the characteristics of different Set and Map implementations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Java Collections Framework Notes

1. Collections Framework Hierarchy:

Iterable

Collection

/ | \

List Set Queue

^ ^ ^

ArrayList HashSet PriorityQueue

LinkedList TreeSet ArrayDeque

SortedSet

NavigableSet

Map

/ \

HashMap SortedMap

TreeMap

2. List, Set and Queue with Example:

List: Ordered, duplicates allowed

Example:
List<String> list = new ArrayList<>();

list.add("Apple"); list.add("Banana");

Set: No duplicates

Set<String> set = new HashSet<>();

set.add("Dog"); set.add("Cat");

Queue: FIFO

Queue<String> queue = new LinkedList<>();

queue.add("A"); queue.add("B");

3. LinkedList Example:

LinkedList<String> list = new LinkedList<>();

list.add("One"); list.add("Two");

4. LinkedList Methods:

add(), addFirst(), addLast(), removeFirst(), get(index)

5. HashMap Example:

HashMap<Integer, String> map = new HashMap<>();

map.put(1, "One");

6. HashMap Methods:

put(), putIfAbsent(), remove(), containsKey(), replace()

7. ArrayList with forEach:

ArrayList<String> items = new ArrayList<>();


items.add("Pen"); items.forEach(System.out::println);

8. Differences: Array vs ArrayList vs Vector vs Stack

9. Set vs Map:

Set - only values, Map - key-value

10. Types of Set and Map:

Set: HashSet, TreeSet, LinkedHashSet

Map: HashMap, TreeMap, LinkedHashMap, Hashtable

11. Stack & Queue Example:

Stack<Integer> stack = new Stack<>();

stack.push(10); stack.pop();

Queue<String> queue = new LinkedList<>();

queue.add("A"); queue.poll();

12. TreeSet and Hashtable:

TreeSet<Integer> ts = new TreeSet<>();

ts.add(3); ts.add(1);

Hashtable<String, String> ht = new Hashtable<>();

ht.put("India", "Delhi");

End of Notes.

You might also like