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

4 Core Java Collections Framework

The document provides an overview of the Java Collections Framework (JCF), detailing its core interfaces such as Collection, List, Set, Queue, Deque, and Map. It includes examples of ArrayList, HashSet, and HashMap, highlighting their features and differences. Additionally, it covers the implementation of Queue and Stack, as well as sorting collections using various methods.

Uploaded by

skoushik.vvdc
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

4 Core Java Collections Framework

The document provides an overview of the Java Collections Framework (JCF), detailing its core interfaces such as Collection, List, Set, Queue, Deque, and Map. It includes examples of ArrayList, HashSet, and HashMap, highlighting their features and differences. Additionally, it covers the implementation of Queue and Stack, as well as sorting collections using various methods.

Uploaded by

skoushik.vvdc
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Core Java – Collections Framework

MCA / [Link] – [Link] Package Reference

1. Collections Framework Overview


The Java Collections Framework (JCF) provides a unified architecture for storing and
manipulating groups of objects. It includes interfaces, implementations (classes), and
algorithms.

1.1 Core Interfaces


Interface Extends Description
Collection Iterable Root interface for all collections
List Collection Ordered, allows duplicates
Set Collection Unordered, no duplicates
Queue Collection FIFO ordering
Deque Queue Double-ended queue
Map — Key-value pairs (not a
Collection)

2. List Interface
2.1 ArrayList
ArrayList<String> list = new ArrayList<>();
[Link]("Java");
[Link]("Python");
[Link]("Python");
[Link]([Link](0)); // Java

Feature ArrayList LinkedList


Internal Structure Dynamic Array Doubly Linked List
Random Access O(1) — Fast O(n) — Slow
Insert/Delete (middle) O(n) — Slow O(1) — Fast
Memory Less overhead More (node pointers)
3. Set Interface
Class Order Null Thread Safe
HashSet No order 1 null allowed No
LinkedHashSet Insertion order 1 null allowed No
TreeSet Sorted (natural) No null No

3.1 HashSet Example


Set<Integer> set = new HashSet<>();
[Link](10); [Link](20); [Link](10); // duplicate ignored
[Link]([Link]()); // 2

4. Map Interface
Class Order Null Keys Thread Safe
HashMap No order 1 null key allowed No
LinkedHashMap Insertion order 1 null key allowed No
TreeMap Sorted by key No null key No
Hashtable No order No null Yes

4.1 HashMap Example


HashMap<String, Integer> map = new HashMap<>();
[Link]("Alice", 95);
[Link]("Bob", 87);
[Link]([Link]("Alice")); // 95
for ([Link]<String,Integer> e : [Link]())
[Link]([Link]() + " = " + [Link]());

5. Queue & Stack


5.1 Queue (LinkedList implementation)
Queue<String> q = new LinkedList<>();
[Link]("A"); [Link]("B");
[Link]([Link]()); // A (FIFO)

5.2 Stack
Stack<Integer> stack = new Stack<>();
[Link](10); [Link](20);
[Link]([Link]()); // 20 (LIFO)
6. Sorting Collections
[Link](list); // natural order
[Link](list, [Link]()); // reverse
[Link]((a, b) -> [Link](b)); // lambda comparator

You might also like