Which map should I use for my requirement?

Home / Uncategorized / Which map should I use for my requirement?

I have two requirements and i can only use map.

Duplicate keys are allowed.(for this i am using multimap)

I have to search for a wild card. Example : if keyset contains "Dave" and "Dave bautista" it will return both.

How to achieve both?

// Returning Map
Map filterObjects = new HashedMap();

// Input List Map
Map map = new HashedMap();
map.put("Dave", null);
map.put("Dave bautista", null);

// User requesting Key Name
String userInput = "Dave bautista";

for (int i = 0; i < map.keySet().size(); i++) { //KeyNames retrieve as element by element from the map String keyName = map.keySet().toArray()[i].toString(); //checks the availability of the userInput with element name if (keyName.contains(userInput)) { // If matched, then put it in to the return Map filterObjects.put(keyName, map.get(keyName)); } } return filterObjects; Read more

Leave a Reply

Your email address will not be published. Required fields are marked *