HashMap

Hey guys I want to retrieve the objects stored in hashmap, but I want to do it in such a way that I can retrieve the first half of the HashMap at one time and at a different point of time retrieve the other half.......is this possible....plz let me knowthanks
[280 byte] By [saranatora] at [2007-10-3 2:52:07]
# 1
define "first half" and "other half"
IanSchneidera at 2007-7-14 20:41:02 > top of Java-index,Java Essentials,New To Java...
# 2
Hard to tell by your question, but LinkedHashMap might be what you are looking for: http://java.sun.com/j2se/1.5.0/docs/api/java/util/LinkedHashMap.html
jbisha at 2007-7-14 20:41:02 > top of Java-index,Java Essentials,New To Java...
# 3

ok......I am implementing a Genetic Algorithm in Java and I have some objects(say 100) stored in a HashMap.... Now I want to use the first 50 objects in the initial part of my program to learn the behaviour and I want to use the last 50 objects check something else ......can I do that.....can I retrieve only half the objects from a HashMap at one time

saranatora at 2007-7-14 20:41:02 > top of Java-index,Java Essentials,New To Java...
# 4

> ok......I am implementing a Genetic Algorithm in Java

> and I have some objects(say 100) stored in a

> HashMap.... Now I want to use the first 50 objects in

> the initial part of my program to learn the behaviour

> and I want to use the last 50 objects check something

> else ......can I do that.....can I retrieve only half

> the objects from a HashMap at one time

Are you sure you want a map? You can pull whatever you want out of a map based on the key.Is sounds like you might instead want two lists with 50 elements each?

zadoka at 2007-7-14 20:41:02 > top of Java-index,Java Essentials,New To Java...
# 5

You might...might want to do something like this:

1) get the entry set from the map

2) create a new list from the set

3) use java.util.Collections.shuffle to randomize the order of the list

4) use List.subList to take a subsets of that list

5) hand off those subsets to different methods, each of which will iterate through their own subsets. Note that the methods wouldn't necessarily know that they're processing subsets.

I have no idea whether this is what you want, but it sounds like maybe it could be.

paulcwa at 2007-7-14 20:41:02 > top of Java-index,Java Essentials,New To Java...