I have this variable :
Hashmap<Integer,HashMap<Integer,Character>> map;
I have the first(Integer) and the third element(Character) and I want to get the 2nd Integer with a function. How do i proceed ? I know how to get value from a normal Hashmap variable but i don't know how to do it with a nested hashmap...
I have already tried this :
import java.util.*;
public class Test{
public static void main(String[] args){
HashMap<Integer,HashMap<Integer,Character>> map;
map = new HashMap<Integer,HashMap<Integer,Character>>();
map.put(0,new HashMap<Integer,Character>());
map.get(0).put(7,'c');
System.out.println((map.get(0)).get('c'));
}
}
I want to print 7 but this print gives me null.
Update : The best way to solve this problem is to change the structure. HashMap isn't designed to get the index from a value. However, there is a way (look below).