Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

K&B Chapter 7 Question 7

 
Douglas Boff Nandi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which collection class(es) allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?
A. java.util.HashSet
B. java.util.LinkedHashSet
C. java.util.List
D. java.util.ArrayList
E. java.util.Vector
F. java.util.PriorityQueue

Answer: only D

I think the B is a correct answer too.

From Java API:LinkedHashSet: This linked list defines the iteration ordering, which is the order in which elements were inserted into the set.
 
Morteza Manavi-Parast
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. That's not right. The only part of the collection which you can get by index is the classes who implement the List interface (Like ArrayList). The signature of the method is: get(int index)
And if you look at the java documentation for LinkedHashSet again, you'll see that you can not find such a method for Set and its implementers.
 
Douglas Boff Nandi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I understand. Thank you!
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic