aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes LinkedHashSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "LinkedHashSet" Watch "LinkedHashSet" New topic
Author

LinkedHashSet

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

From K and B book

Optionally, you can construct a LinkedHashSet
so that it maintains the order in which elements were last accessed, rather than the
order in which elements were inserted.


How do I contruct such a LinkedHashSet?
Rob Harris
Greenhorn

Joined: Nov 11, 2004
Posts: 10
try

http://javaalmanac.com/egs/java.util/coll_SetOrder.html

Rob
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

The example maintains the order of insertion but does not order elements based on last access, right?.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
The example maintains the order of insertion but does not order elements based on last access, right?.

Correct. As far as I can tell, there is no way to create a LinkedHashSet which uses access order. If your quote from Head First Java is accurate, I think that K&B may have confused LinkedHashSet with LinkedHashMap, which does have this option. (Use the new LinkedHashMap(int, float, boolean) constructor for this.) No such access-order capability was put into LinkedHashSet. I suggest submitting this to K&B via their web site. Or we could just see if one of them sees this...


"I'm not back." - Bill Harding, Twister
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

Thanks Jim for the clarification.

If your quote from Head First Java is accurate, I think that K&B may have confused LinkedHashSet with LinkedHashMap, which does have this option.


I have pasted directly from the ebook.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8764
    
    5
Hi Guys,

Yup - it's an error all right...

Funny thing is, I thought it had been corrected a few printings ago, I'm very sorry this one slipped through the cracks!

So, to clarify:

LinkedHashMap has a constructor that allows access via "last access",

LinkedHashSet does NOT :roll:

HTH,

Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: LinkedHashSet
 
Similar Threads
collecition class
LinkedHashSet and LinkedHashMap
Another errata entry to SCJP Study Guide 1.4?
TreeSet
is LinkedHashSet ordered?