This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes LinkedHashSet confusion Chapter-7 Question-7 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "LinkedHashSet confusion Chapter-7 Question-7" Watch "LinkedHashSet confusion Chapter-7 Question-7" New topic
Author

LinkedHashSet confusion Chapter-7 Question-7

Ben Pheonix
Ranch Hand

Joined: Dec 11, 2012
Posts: 46
    
    1

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


Twitter:ben_pheonix
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3506
    
  14
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: 743
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

Joined: Dec 11, 2012
Posts: 46
    
    1

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: 3506
    
  14
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: LinkedHashSet confusion Chapter-7 Question-7