HashSet<E> (Java Questions)
Class HashSet<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
java.util.HashSet<E>
Type Parameters:
E - the type of elements maintained by this set
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>
Direct Known Subclasses:
JobStateReasons, LinkedHashSet
- What is a hashset?
Answer:
A hashset is an unordered and unsorted set.
- What is a LinkedHashSet?
Answer:
A LinkedHashSet is an ordered but not sorted set that maintains the order in which the objects were inserted.
- In what order are the elements of a hashtable placed?
Answer:
In a hashtable the elements are placed in a chaotic order based on the hashcode of the key.
- What does it mean when a collection is ordered?
Answer:
When a collection is ordered, it means you can iterate through the collection in a specific (not-random) order.
- How does an ArrayList keep order?
Answer:
An ArrayList keeps the order established by the element's index position (just like an array). An ArrayList maintains order by means of an index position.
- How does the LinkedHashSet keep order?
Answer:
The LinkedHashSet keeps the order established by insertion.
- How do you insert an element at a specific index position in an ArrayList ?
Answer:
To insert an element in ArrayList at a specific position, use ArrayList.add(index, element) function where index (= i-1) specifies ith position and the element is the one that is inserted.
When the element is inserted, the elements from i-th position are shifted right side by a position.
- How do you describe collections that maintain the natural order of elements?
Answer:
One says that these collections are ordered and sorted.
- What is a sorted collection?
Answer:
A sorted collection means that the order in the collection is determined according to some rule or rules, known as the sort order.
- What is sorting based on ?
Answer:
Sorting is done based on properties of the object's themselves.