Search code examples
javageneric-collections

Unable to retrieve all the key for a Map(HashMap)?


I am working on a client-server application in which server sends the indication and client receives those indication.The Map is declared as

private static Map<key,value> obj=new HashMap<key,value>();

The Map is getting the values through synchronised(obj) in constructor of the value Class

obj.put(this,this);

I am trying to retrieve the all the keys for this Map. I used Set<key> t=Map.KeySet(); but this throws a compile error saying can not found symbol :KeySet() in interface java.util.Map. Note:key is interface and value is the class in which Map is Declared.


Solution

  • Check the Map API once. Map is interface and you are trying to use the keySet() like you call a static method.

    You should call the methods on the object created.

    you should use obj.keySet()

    Map Api