Tags / collections
Describing the Java Deque collection interface
A Deque is a double-ended-queue. It is a collection of elements that supports the insertion and removal of elements at both end points. It implements both Stack and Queue at the same time. This interface defines following methods: void addFirst(E e) void addLast(E e) boolean offerFirst(E e) boolean offerLast(E e) E…
Describing the Java List collection interface
List is an ordered collection that can contain duplicates. In addition to the Collection interface methods, the List interface includes the following: Positional access: manipulating the elements by their index in the list. This includes methods such as: get, set, add, addAll, remove. Search: methods indexOf and…
Describing the Java Map collection. Difference between other collections.
Map is a collection that stores key-value pairs. A map cannot contain duplicate keys. What is the main difference between Map and other collections? The main difference between Map and other collections is that it contains key and value. It doesn’t inherit from Collection interface. The Map interface includes methods…
Describing the Java Set collection interface
A Set is a Collection that cannot contain duplicates. The Set interface extends Collection interface but has no specific methods. It adds the restriction that duplicates are prohibited. This interface also adds a stronger contract on the behavior of the equals and the hashcode methods, allowing Set instances to be…
Java Collections hierarchy
(Self-explanatory image above)
What benefits does JCF provide?
Java Collections Framework provides the following benefits: Reduces programming effort: you don’t need to invent the wheel anymore, JCF provides useful data structures and algorithms. Increases program speed and quality: JCF provides high-performance, high-quality implementations of useful data structures and…
What data can be stored in a collection?
You can store anything but primitives. To store primitives consider using wrappers (Integer for int, Double for double, etc…). For example, you can store your own classes: To store primitives: Notice, that you can add primitives, since it will be wrapped automatically: