• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

LinkedHashSet confusion Chapter-7 Question-7

 
Ranch Hand
Posts: 46
1
Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Thanks for the input. I was confusing it with LinkedList concept. Thanks a ton again.
Ben
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wonder why E- java.util.Vector is not included in given correct option ?
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes , thanks Joanne. I see the question.

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch Raja Sri !
 
Raja Sri
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You!
 
Raja Sri
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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









 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Are you here to take over the surface world? Because this tiny ad will stop you!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic