How do I get integer from the dictionary? Thanks for help !
Hashtable<Integer, Integer> groupsPostId = new Hashtable<Integer, Integer>();
groupsPostId.put(1, 100);
Integer postId = groupsPostId.get(1);
Error: error: incompatible types: Object cannot be converted to Integer
CodePudding user response:
Try casting :
Integer postId = (Integer) groupsPostId.get(1);
CodePudding user response:
You should replace the synchronized class "Hashtable" with an unsynchronized one such as "HashMap". Nobody doesn't use Hashtable since java 1.5 I think. Also, your snippet doesn't make any problem when I put its in my IDE