0% found this document useful (0 votes)
105 views2 pages

Java Collections Quick Reference Guide

Uploaded by

Aman kumar
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)
105 views2 pages

Java Collections Quick Reference Guide

Uploaded by

Aman kumar
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

Java Collections Cheat Sheet

ArrayList
• Syntax: ArrayList list = new ArrayList<>();
• Insertion: [Link](element); [Link](index, element);
• Access: [Link](index);
• Update: [Link](index, element);
• Deletion: [Link](index); [Link](Object);
• Size: [Link]();
• Looping: for(Type x : list) { } or [Link](...);
• Sort: [Link](list);

Stack
• Syntax: Stack stack = new Stack<>();
• Push: [Link](element);
• Pop: [Link]();
• Peek: [Link]();
• Check empty: [Link]();
• Size: [Link]();

Queue
• Syntax: Queue queue = new LinkedList<>();
• Enqueue: [Link](element); [Link](element);
• Dequeue: [Link](); [Link]();
• Peek: [Link](); [Link]();
• Size: [Link]();

PriorityQueue (Min Heap & Max Heap)


• Min Heap Syntax: PriorityQueue pq = new PriorityQueue<>();
• Max Heap Syntax: PriorityQueue pq = new PriorityQueue<>([Link]());
• Insertion: [Link](element);
• Peek: [Link]();
• Deletion: [Link]();
• Size: [Link]();

HashMap (unordered)
• Syntax: HashMap map = new HashMap<>();
• Insert: [Link](key, value);
• Access: [Link](key);
• Delete: [Link](key);
• Size: [Link]();
• Check Key: [Link](key);
• Looping: for([Link] e : [Link]()) { }
LinkedHashMap (ordered)
• Syntax: LinkedHashMap map = new LinkedHashMap<>();
• Maintains insertion order.
• Methods same as HashMap.

HashSet (unordered)
• Syntax: HashSet set = new HashSet<>();
• Insert: [Link](element);
• Delete: [Link](element);
• Check: [Link](element);
• Size: [Link]();
• Looping: for(Type x : set) { }

LinkedHashSet (ordered)
• Syntax: LinkedHashSet set = new LinkedHashSet<>();
• Maintains insertion order.
• Methods same as HashSet.

LinkedList (Singly & Doubly)


• Syntax: LinkedList list = new LinkedList<>();
• Insertion: [Link](element); [Link](element); [Link](element);
• Deletion: [Link](); [Link](); [Link]();
• Access: [Link](index);
• Size: [Link]();
• Doubly LinkedList is supported internally by LinkedList class.

Pair
• Syntax: [Link] pair = new [Link]<>(key, value);
• Access: [Link](); [Link]();
• Assign: [Link](newValue);

You might also like