This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LinkedHashSet confusion Chapter-7 Question-7

 
Ben Pheonix
Ranch Hand
Posts: 46
1
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


A- java.util.HashSet
B- java.util.LinkedHashSet
C- java.util.List
D- java.util.ArrayList
E- java.util.Vector
F- java.util.PrioirityQueue


It says only D is correct. Why B is not included? It also provides index based insertion. Please help.
Thanks,
Ben
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Himai Minh
Ranch Hand
Posts: 1296
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 46
1
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Thanks for the input. I was confusing it with LinkedList concept. Thanks a ton again.
Ben
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder why E- java.util.Vector is not included in given correct option ?
 
Raja Sri
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I too, we can access Vector by its index and it grow or shrink as needed.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes , thanks Joanne. I see the question.

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch Raja Sri !
 
Raja Sri
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You!
 
Raja Sri
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic