This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund 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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply 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
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
    
    9
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
    
    9
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: LinkedHashSet confusion Chapter-7 Question-7
 
Similar Threads
HFEJB: Coffee Cram Entity Beans
What version of Net Beans does your book cover ?
Need Clarity about Enum???
Doubt in K&B - Generics & Collections - Question 8
Take the Dr. Phil Test