Ordered by index is similar to contents in an array. Here retrieval of elements from the collection is based on the index. You can add or remove elements from any indexed position whereas in the case insertion order, you cannot access elements in any order. Here retreival of elements is similar to that of a stack or a queue.
which of the following is not true of the java.util.LinkedHashSet class and why?
1 - it allows you to grow or shrink its size.
2 - it provides indexed access to its elements.
3 - its methods are not synchronized.
Hi, Glen. I want to check answer with you to quiz myself.
1. is correct as you can add or remove from linked hash set.
2. is incorrect because you cannot use get(0), get(1) to retrieve each element, unlike linked list.
3. is correct as I checked the open source, the LinkedHashSet overrides the methods in HashSet. Those methods are not synchronized.
So far, as I remember K&B's book, only Vector has synchronized methods, which is slow in performance. That is why Vector is an obselete class based on some IDE such as NetBean Platform.
What are the correct answers?
Joined: Oct 05, 2010
ordered by index means: if i ask for collection i will get the element at zero, it may or may not have been the first element added to the collection.
ordered by insertion order means: if i ask for collection i will get the first element that was added to the set. the first element added to the set will always reside in collection.