JAVA logic help

Associate
Joined
17 Nov 2008
Posts
209
Hi

  • In one method, I'm storing objects into a HashMap(Object-A, Object-B)
  • Another method I'm searching through the HashMap looking for specific item by comparing Object-B to Object-C.
  • I find a match(can be multiple)


I then want to return the found Item(s) as HashMap

Any ideas?
 
Last edited:
Iterate over the values in the first HashMap using its values() method and then compare each value to Object-C. In that method create a new HashMap and then add any matching results to it as you search. Finally return that HashMap.
 
You need to create a new HashMap in which you will store the object founds. Then return the new HashMap.

Pseudocode:

Create an empty HashMap;

For each object in HashMap {
Check if it is the one we look for, and if it is copy key-object in new HashMap;
}

Return the HashMap;
 
Back
Top Bottom