I am using below code to get & process value from google HashMultimap
HashMultimap hmm = new HashMultimap();
HashMultimap hmm2 = new HashMultimap();
Element ele;
:
hmm2.put("name","Amit");
hmm.put("Amit",ele);
hmm.put("rohit",hmm2);
:
Iterator itr = hmm.keys().iterator();
String ky = (String) itr.next();
System.out.println(hmm.get(ky));
ky = (String) itr.next();
System.out.println(hmm.get(ky));
In above code, if map element(or entry) is Element type then i want to do some operation. If it is HashMultimap type then do some other operation. How can i check and pass the object to another function.
Since this is a
HashMultimapwhich is also aSetMultimap, when you callhmm.get(ky)the value returned is going to be aSetof all the values for that key. You should then be able to iterate through each of the values in theSetand useinstanceofon those values. If there are not going to be multiple values for each key, you shouldn’t be using aMultimapto begin with and should just use normalHashMap.The key point is that calling
get()on aHashMultimapreturns aSetof values and not a single value.