| Author |
LinkedHashSet confusion Chapter-7 Question-7
|
Ben Pheonix
Greenhorn
Joined: Dec 11, 2012
Posts: 6
|
|
Hello.
I have a confusion in self test question of K&B. The chapter is 7 and question number is 7. It asks which collection allows to grow and shrink its size
and provides indexed access to its elements. The options are
It says only D is correct. Why B is not included? It also provides index based insertion. Please help.
Thanks,
Ben
|
Twitter:ben_pheonix
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
Ben Pheonix wrote:Why B is not included? It also provides index based insertion.
Does it ? How does it do that ? Can you show us some example code ?
|
Joanne
|
 |
Himai Minh
Ranch Hand
Joined: Jul 29, 2012
Posts: 289
|
|
|
For ArrayList, we can use get(int index) to get an element at position index. But for LinkedHashSet, we don't have such a method.
|
 |
Ben Pheonix
Greenhorn
Joined: Dec 11, 2012
Posts: 6
|
|
Hello,
Thanks for the input. I was confusing it with LinkedList concept. Thanks a ton again.
Ben
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
|
I wonder why E- java.util.Vector is not included in given correct option ?
|
 |
Raja Sri
Greenhorn
Joined: Jan 09, 2013
Posts: 4
|
|
|
I too, we can access Vector by its index and it grow or shrink as needed.
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
Seetharaman Venkatasamy wrote:I wonder why E- java.util.Vector is not included in given correct option ?
I was going to agree with you but thought I would see if this problem had been mentioned before.
I found this post where the full question is given.
Strangely enough the OP there also thought B was a correct answer.
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Yes , thanks Joanne. I see the question.
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Welcome to CodeRanch Raja Sri !
|
 |
Raja Sri
Greenhorn
Joined: Jan 09, 2013
Posts: 4
|
|
|
Thank You!
|
 |
Raja Sri
Greenhorn
Joined: Jan 09, 2013
Posts: 4
|
|
Option E- java.util.Vector is not correct as question also mentioned that methods in that collection should not be synchronized and Vector methods are synchronized.
Here is the question :
7. 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? (Choose all that apply.)
A.java.util.HashSet
B.java.util.LinkedHashSet
C.java.util.List
D.java.util.ArrayList
E.java.util.Vector
F.java.util.PriorityQueue
|
 |
Zhenyi Luo
Ranch Hand
Joined: Sep 03, 2012
Posts: 33
|
|
Raja Sri wrote:Option E- java.util.Vector is not correct as question also mentioned that methods in that collection should not be synchronized and Vector methods are synchronized.
Here is the question :
7. 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? (Choose all that apply.)
A.java.util.HashSet
B.java.util.LinkedHashSet
C.java.util.List
D.java.util.ArrayList
E.java.util.Vector
F.java.util.PriorityQueue
Thanks
|
 |
 |
|
|
subject: LinkedHashSet confusion Chapter-7 Question-7
|
|
|