hashCode() and hashSet implementations (Java)
- Do HashSets guarantee any ordering?
Answer:
Java HashSet does not guarantee any insertion orders of the set but it allows null elements.
- What must be true in order for a collection to be sorted?
Answer:
Whenever you want a collection to be sorted its elements must be mutually comparable.
- What must be true when you use a class that implements Map?
Answer:
Any classes you use as a part of the keys for that map must override the 1) hashCode() and 2) equals methods.
- What does the PriorityQueue method "offer" do?
Answer:
The "offer" method is used to add elements to the PriorityQueue.
- What does the subSet method do with respect to TreeSets?
Answer:
subSet(s, b*, e, b*)
Returns a subset starting at element s and ending just before element e. [SCJP P590 By K.S.]
-
With respect to TreeMaps what does the method "higherkey" do?
Answer:
TreeMap.higherKey(key)
Return the lowest key which is greater than the key.
- What do the methods 1) poll and 2) peak do with respect to Queues?
Answer:
The remove() and poll() methods remove and return the head of the queue.
Exactly which element is removed from the queue is a function of the queue's ordering policy, which differs from implementation to implementation.
The element() and peek() methods return, but do not remove, the head of the queue.
- Which method does the Comparable interface have to implement?
Answer:
The Comparable interface has to implement the compareTo() method.
- Which method does the Comparator interface use?
Answer:
The Comparator interface makes use of the compare() method.
- Which 3 methods exist in Queues which do not exist in other collections?
Answer:
- peek()
- poll()
- offer()