0% found this document useful (0 votes)
2 views1 page

Java Collections Cheatsheet

Uploaded by

sou.dutta.14
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)
2 views1 page

Java Collections Cheatsheet

Uploaded by

sou.dutta.14
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/ 1

Java Collections Framework - Concise Cheat Sheet

Collection (Root Interface)


- boolean add(E e) - boolean remove(Object o) - boolean contains(Object o) - int
size() - void clear() - Iterator iterator()

List (ArrayList, LinkedList, Vector)


Syntax: List list = new ArrayList<>(); - void add(int index, E element) - E get(int
index) - E set(int index, E element) - E remove(int index) - boolean contains(Object
o)

Stack
Syntax: Stack stack = new Stack<>(); - E push(E item) - E pop() - E peek() - boolean
empty() - int search(Object o)

Set (HashSet, LinkedHashSet, TreeSet)


Syntax: Set set = new HashSet<>(); - boolean add(E e) - boolean remove(Object o) -
boolean contains(Object o) - int size() - void clear()

Queue / Deque (LinkedList, PriorityQueue, ArrayDeque)


Syntax: Queue q = new LinkedList<>(); - boolean offer(E e) - E poll() - E peek() -
void addFirst(E e) - void addLast(E e) - E removeFirst() - E removeLast()

Map (HashMap, LinkedHashMap, TreeMap, Hashtable)


Syntax: Map map = new HashMap<>(); - V put(K key, V value) - V get(Object key) -
boolean containsKey(Object key) - boolean containsValue(Object value) - V
remove(Object key) - Set keySet() - Collection values() - Set> entrySet()

StringBuilder / StringBuffer
Syntax: StringBuilder sb = new StringBuilder(); - StringBuilder append(String s) -
StringBuilder insert(int offset, String s) - StringBuilder delete(int start, int
end) - StringBuilder replace(int start, int end, String s) - StringBuilder reverse()
- int capacity() - void ensureCapacity(int minCapacity)

Utility Classes
Collections: - Collections.sort(list) - Collections.reverse(list) -
Collections.shuffle(list) Arrays: - Arrays.asList(array) - Arrays.sort(array) -
Arrays.binarySearch(array, key)

You might also like