Possible Duplicate:
Java Hashmap: How to get key from value?
I have a hashmap
private static HashMap<ObjectClass, UUID> projectileSet = new HashMap<ObjectClass, UUID>();
and an unfinished method where i want to return the ObjectClass that corresponds to the UUID
public static LegendaryItem getClass(UUID uniqueId) {
return projectileSet.getKey(uniqueId);
}
You can return key from HashMap by using "KeySet()" method.
HashMap objH=new HashMap<>();
Set objSet=objH.keySet();
public static LegendaryItem getClass(UUID uniqueId) {
Iterator objItr=objSet.iterator();
while(objItr.hasNext()){
UUID objStr=(UUID) objItr.next();
if(objStr.equals(uniqueId)){
return objStr;
}
}
}
Iterate the ObjSet and get each key