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
> 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?
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.