• Post Reply Bookmark Topic Watch Topic
  • New Topic

JDK1.3: Alternatives of LinkedHashMap  RSS feed

 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!