i have some keys which are pointing to many values in a multimap. how can i retrieve the key basing on the value present in the multimap. Here is my code.
package com.manoj;
import java.util.Set;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
public class GuavaMap
{
public static void main(String[] args)
{
Multimap regions = ArrayListMultimap.create();
regions.put("asia", "afganistan");
regions.put("asia", "bangladesh");
regions.put("asia", "inida");
regions.put("asia", "japan");
regions.put("asia", "burma");
regions.put("europe", "andorra");
regions.put("europe", "austria");
regions.put("europe", "belgium");
regions.put("europe", "cyprus");
regions.put("oceania","australia");
regions.put("oceania", "fiji");
regions.put("oceania", "nauru");
Set<String> keys = regions.keySet();
System.out.println("key\t\t\t"+"values\t\t\t");
System.out.println();
String comp = null;
for(String key : keys)
{
System.out.print(key);
System.out.println(regions.get(key));
}
}
}
the above code is providing me the output as follows
i need the region name basing on the country.
Example: if i give "australia" output should be "oceania"