Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Java Collection Classes

Derk Norton edited this page Sep 15, 2015 · 14 revisions

The Java Collection Classes inherit from the framework abstractions and provide the concrete functionality desired by the programmer.

Java Collection Classes

Bag<E>

This concrete class implements an ordered collection that allows duplicate elements. The elements are automatically ordered using a comparator that implements the standard java.util.Comparator<E> interface. The default comparator uses the java.lang.Comparable<T>.compareTo(T object) method for the element type. This class implements the following methods:

  • String toString()
  • String toString(String indentation)
  • boolean isEmpty()
  • int getSize()
  • void toArray(E[] array)
  • Iterator<E> createIterator()
  • boolean containsElement(E element)
  • boolean containsAll(java.lang.Iterable<? extends E> elements)
  • boolean containsAny(java.lang.Iterable<? extends E> elements)
  • int getIndex(E element)
  • E getElement(int index)
  • Accessible<E> getElements(int firstIndex, int lastIndex)
  • void removeAll()
  • java.util.Comparator<? super E> getComparator()

It also implements these (static) functions:

  • <E> Bag<E> difference(Bag<E> bag1, Bag<E> bag2)
  • <E> Bag<E> aggregation(Bag<E> bag1, Bag<E> bag2)

Set<E>

This concrete class implements an ordered collection that does not allow duplicate elements. The elements are automatically ordered using a comparator that implements the standard java.util.Comparator<E> interface. The default comparator uses the java.lang.Comparable<T>.compareTo(T object) method for the element type. This class implements the following methods:

  • String toString()
  • String toString(String indentation)
  • boolean isEmpty()
  • int getSize()
  • void toArray(E[] array)
  • Iterator<E> createIterator()
  • boolean containsElement(E element)
  • boolean containsAll(java.lang.Iterable<? extends E> elements)
  • boolean containsAny(java.lang.Iterable<? extends E> elements)
  • int getIndex(E element)
  • E getElement(int index)
  • Accessible<E> getElements(int firstIndex, int lastIndex)
  • void removeAll()
  • java.util.Comparator<? super E> getComparator()

It also implements these (static) functions:

  • <E> Set<E> and(Set<E> set1, Set<E> set2)
  • <E> Set<E> sans(Set<E> set1, Set<E> set2)
  • <E> Set<E> or(Set<E> set1, Set<E> set2)
  • <E> Set<E> xor(Set<E> set1, Set<E> set2)

List<E>

This concrete class implements a sortable collection that uses implicit numeric (ordinal) indexes to reference its elements. The elements are maintained in the order that they are placed in the list and can be manually reordered at any time. A list may also be sorted using a sorter and comparator that implement as specific sorting algorithm. The default comparator uses the java.lang.Comparable<T>.compareTo(T object) method for the element type. This class implements the following methods:

  • String toString()
  • String toString(String indentation)
  • Iterator<E> createIterator()
  • Manipulator<E> createManipulator()
  • boolean isEmpty()
  • int getSize()
  • void toArray(E[] array)
  • boolean containsElement(E element)
  • boolean containsAll(java.lang.Iterable<? extends E> elements)
  • boolean containsAny(java.lang.Iterable<? extends E> elements)
  • int getIndex(E element)
  • E getElement(int index)
  • Accessible<E> getElements(int firstIndex, int lastIndex)
  • int getIndex(E element)
  • E getElement(int index)
  • Indexed<E> getElements(int firstIndex, int lastIndex)
  • void insertElement(E element, int index)
  • void insertElements(java.lang.Iterable<? extends E> elements, int index)
  • E replaceElement(E element, int index)
  • E removeElement(int index)
  • Indexed<E> removeElements(int firstIndex, int lastIndex)
  • void removeAll()
  • void shuffleElements()
  • void sortElements()
  • void sortElements(java.util.Comparator<? super E> comparator)
  • void sortElements(Sorter<E> sorter, java.util.Comparator<? super E> comparator)

It also implements these (static) functions:

  • <E> List<E> concatenation(List<E> list1, List<E> list2)

Dictionary<E>

This concrete class implements a sortable collection that uses explicit String keys to reference its elements. The elements are maintained in the order that they are placed in the dictionary and can be manually reordered at any time. A dictionary may also be sorted using a sorter and comparator that implement as specific sorting algorithm. The default comparator uses the java.lang.String.compareTo(String object) method for the element type. This class implements the following methods:

  • String toString()
  • String toString(String indentation)
  • Iterator<Association<String, V>> createIterator()
  • Manipulator<Association<String, V>> createManipulator()
  • boolean isEmpty()
  • int getSize()
  • void toArray(Association<String, V>[] array)
  • boolean containsElement(Association<String, V> element)
  • boolean containsAll(java.lang.Iterable<? extends Association<String, V>> elements)
  • boolean containsAny(java.lang.Iterable<? extends Association<String, V>> elements)
  • int getIndex(Association<String, V> element)
  • Association<String, V> getElement(int index)
  • Accessible<Association<String, V>> getElements(int firstIndex, int lastIndex)
  • int getIndex(Association<String, V> element)
  • Association<String, V> getElement(int index)
  • Indexed<Association<String, V>> getElements(int firstIndex, int lastIndex)
  • Accessible<String> getKeys()
  • Accessible<String> getValues()
  • Accessible<Association<String, V>> getAssociations()
  • V getValue(String key)
  • void setValue(String key, V value)
  • V removeValue(String key)
  • void removeAll()
  • void shuffleElements()
  • void sortElements()
  • void sortElements(java.util.Comparator<? super Association<String, V>> comparator)
  • void sortElements(Sorter<Association<String, V>> sorter, java.util.Comparator<? super Association<String, V>> comparator)

It also implements these (static) functions:

  • <V> Dictionary<V> concatenation(Dictionary<V> dictionary1, Dictionary<V> dictionary2)
  • <V> Dictionary<V> reduction(Dictionary<V> dictionary, Set<String> keys)

Map<K, V>

This concrete class implements a sortable collection that uses explicit arbitrary type keys to reference its elements. The elements are maintained in the order that they are placed in the map and can be manually reordered at any time. A map may also be sorted using a sorter and comparator that implement as specific sorting algorithm. The default comparator uses the java.lang.Comparable<T>.compareTo(T object) method for the element type. This class implements the following methods:

  • String toString()
  • String toString(String indentation)
  • Iterator<Association<K, V>> createIterator()
  • Manipulator<Association<K, V>> createManipulator()
  • boolean isEmpty()
  • int getSize()
  • void toArray(Association<K, V>[] array)
  • boolean containsElement(Association<K, V> element)
  • boolean containsAll(java.lang.Iterable<? extends Association<K, V>> elements)
  • boolean containsAny(java.lang.Iterable<? extends Association<K, V>> elements)
  • int getIndex(Association<K, V> element)
  • Association<K, V> getElement(int index)
  • Accessible<Association<K, V>> getElements(int firstIndex, int lastIndex)
  • int getIndex(Association<K, V> element)
  • Association<K, V> getElement(int index)
  • Indexed<Association<K, V>> getElements(int firstIndex, int lastIndex)
  • Accessible<K> getKeys()
  • Accessible<V> getValues()
  • Accessible<Association<K, V>> getAssociations()
  • V getValue(K key)
  • void setValue(K key, V value)
  • V removeValue(K key)
  • void removeAll()
  • void shuffleElements()
  • void sortElements()
  • void sortElements(java.util.Comparator<? super Association<K, V>> comparator)
  • void sortElements(Sorter<Association<K, V>> sorter, java.util.Comparator<? super Association<K, V>> comparator)

It also implements these (static) functions:

  • <K, V> Map<K, V> concatenation(Map<K, V> map1, Map<K, V> map2)
  • <K, V> Map<K, V> reduction(Map<K, V> map, Set<K> keys)

Queue<E>

This concrete class implements a closed collection that restricts access to its elements to a first in first out (FIFO) order. It is thread safe so that multiple threads can be putting elements on the queue while other threads are removing elements from the queue. This class implements the following methods:

  • Iterator<E> createIterator()
  • boolean isEmpty()
  • int getSize()
  • void addElement(E element)
  • E removeElement()
  • E getHead()
  • void removeAll()
  • void toArray(E[] array)
  • String toString()
  • String toString(String indentation)

Stack<E>

This concrete class implements a closed collection that restricts access to its elements to a last in first out (LIFO) order. This class implements the following methods:

  • Iterator<E> createIterator()
  • boolean isEmpty()
  • int getSize()
  • void pushElement(E element)
  • E popElement()
  • E getTop()
  • void removeAll()
  • void toArray(E[] array)
  • String toString()
  • String toString(String indentation)