Collections Section Index
What purpose does the newSetFromMap() method offer if I can just create something like a HashSet instead of a HashMap?
The Set returned by newSetFromMap() functions with the same ordering and concurrency characteristics of the map it is based off of. Some Map implementations also have a related Set implement, so u...more
What is a Deque?
A Deque is a double ended queue, allowing inserting and removing from both ends.
What are the differences between Vector and ArrayList? Which is best to use?
Vector and ArrayList are very similar. Both of them represent a 'growable array', where you access to the elements in it through an index.
ArrayList it's part of the Java Collection Framework, an...more
Why should all Comparators be Serializable?
If you pass a Comparator that doesn't implement Serializable into a collection like a TreeMap, that collection will automatically be non-serializable. It is best to flag all Comparator implementat...more
What does Class<String> mean?
Class<String> is the generics way of writing String.class. It allows you to improve type safety.
What does Class<String> mean?
Class<String> is the generics way of writing String.class. It allows you to improve type safety.
What is the natural ordering of a Boolean? Does FALSE come first or second?
Boolean.FALSE < Boolean.TRUE
How do I create a multimap in Java?
Typically a Map maps a key to a single value. To have a multimap, the values of a Map should be a List instead. Thus there can be multiple values in the List associated with a single key.more
What is a multimap?
A multimap is a map where a single key can map to multiple values. (And a value can be associated with multiple keys.)
What is a multimap?
A multimap is a map where a single key can map to multiple values.
How can I detect if a duplicate is added to a Set?
The add() method returns a boolean. If the set did not previously contain the element, true is returned. If the set previoulsy did contain the element, false is returned. Of course, you can also c...more
Is it better to use a for-each loop or an Iterator with a collection?
It depends on what you need to do. The remove() method of an Iterator is the safe way to remove elements from an underlying collection. You can't safely remove elements with a for-each loop. For j...more
Why do I keep getting an UnsupportedOperationException thrown when I try some collection operations?
Several methods of the collection interfaces are considered optional. If an unsupported operation is called, that is when you'll see the UnsupportedOperationException thrown. The javadoc for a col...more
What implementations of the Deque interface does Java offer?
ArrayDeque offers an array backed deque. LinkedList offers a linked list version. LinkedBlockingDeque offers an optionally bounded blocking version.
How do you pronounce Deque?
Deque is pronounced like deck, not de-queue.