Collections

Java Collections Methods - 31 Cards
Click here to toggle all cards
List.of()
Creates an immutable list with specified elements
list.size()
Returns the number of elements in the List
list.contains()
Checks if the list contains a given element and returns a boolean value.
list.indexOf()
Returns the index of the first occurrence of the specified element in the list.
list.endsWith()
Returns a boolean value checking if a list ends with a specified element.
arrayList.add()
Adds an element to the end of the list.
arrayList.addAll()
Add all elements of one List to ArrayList.
arrayList.set()
Used to replace an element at a specified index.
arrayList.remove()
Removes the element at the specified index from the ArrayList.
Collections.sort()
Used to sort the elements in a collection.
treeSet.floor()
Returns the greatest element in the TreeSet less than or equal to the given element.
treeSet.lower()
Return the greatest element in the TreeSet less than the given element.
treeSet.ceiling()
Returns the least element greater than or equal to the given element.
treeSet.subSet()
Returns a subset of the TreeSet within a specified range.
treeSet.headSet()
Returns a subset of elements that are less than the specified element in a TreeSet.
treeSet.tailSet()
Returns a view of the portion of the set greater than or equal to the specified element.
PriorityQueue<>()
Data structure that orders elements based on priority in Java.
queue.poll()
Retrieves and removes the head of the queue, or returns null if the queue is empty.
queue.offer()
The method to insert an element into the Queue in Java.
hashMap.put()
Inserts a key-value mapping into the HashMap.
hashMap.keySet()
Returns a set of keys stored in the HashMap object.
hashMap.values()
Returns a set of values contained in the HashMap.
TreeMap<>()
A Class in Java that implements the Map interface using a red-black tree.
treeMap.put()
Used to insert key-value pairs into a TreeMap.
treeMap.higherKey()
Returns the least key greater than the given key, or null if no key.
treeMap.ceilingKey()
Returns the lowest key greater than or equal to the given key.
treeMap.lowerKey()
Returns the greatest key less than the given key.
treeMap.floorKey()
Returns the greatest key less than or equal to the given key.
treeMap.firstEntry()
Returns the first key-value mapping of the TreeMap.
treeMap.lastEntry()
Returns the last key-value pair in the TreeMap.
treeMap.subMap()
Returns a portion of TreeMap based on specified range.