my dog learned polymorphism
The moose likes Beginning Java and the fly likes JDK1.3: Alternatives of LinkedHashMap 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 » Java » Beginning Java
Reply Bookmark "JDK1.3: Alternatives of LinkedHashMap" Watch "JDK1.3: Alternatives of LinkedHashMap" New topic
Author

JDK1.3: Alternatives of LinkedHashMap

Ankur Sharma
Ranch Hand

Joined: Dec 27, 2005
Posts: 1234
Hi Ranchers,

I want to use the functionality of LinkedHashMap in Jdk1.3 but I don't know whether is there any Collection in JDK 1.3 which may work as LinkedHashMap.

My Usage is to use key-value pair and then if I try for retreival of Data then it should be in the same order as it was inserted originally.

Advance Thanks for Help.


The Best way to predict your future is to create it
Ankur Sharma
vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580
Just an idea

Create one valueObject with 2 fields(Key and value), pack up in ArrayList,While retrieval unpack it.
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12924
    
    3

As far as I know there is no class in JDK 1.3 that does the same as what LinkedHashMap does.

However, behind the scenes, LinkedHashMap is just a HashMap together with a LinkedList. When you insert an item into it, it is inserted into the map as well as added to the list. The list is used to keep track of the order in which elements are inserted.

You could write something like LinkedHashMap yourself using this idea.

Another idea: Ofcourse it would be best to upgrade a newer version of Java, but probably you're stuck with 1.3 for some reason. Are you allowed to add third-party libraries to your project? The Apache Jakarta Commons Collections library contains a class LinkedMap that does more or less the same as LinkedHashMap.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ankur Sharma
Ranch Hand

Joined: Dec 27, 2005
Posts: 1234
Thankx Vidya & Jasper for your prompt reply, But yes this is fact, that because of some conditions I am bound with using JDK 1.3 and another thing is I cann't use any another library. But yes Jasper now I am going to design your first point.

May it helps me.

In the mean time if someone has some better idea then please do let me know.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDK1.3: Alternatives of LinkedHashMap
 
Similar Threads
Want Map without sort
Maintaining order in the map
Use of memory == less? GC : Soft ref
Iteration of a HashMap in the order of insertion
Regarding sorting of TreeMap