Class Test is my separate class which has two field of String and Float type, I am using this class with List Collections which will be finally populated as values into HashMap.
But when I try to populate the Map with a key and the List objects (values) into the map, Java does not seem to accept it as it is not valid syntax:
ArrayList <Test> list = new ArrayList <Test> ();
Map<Integer, ArrayList <Test>> mp = new HashMap<Integer, ArrayList <Test>>();
list.add(new Telephone ( 0.9 , "A"));
list.add(new Telephone(5.1 , "A"));
mp.put(0,list.get(0)); // this Does Not work :(, it should work
Output:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method put(Integer, ArrayList<Telephone>) in the type
Map<Integer,ArrayList<Telephone>> is not applicable for the arguments
(int, Telephone) at Main.main(Main.java:64)
Going by your requirement you told in comments and question above I think you need following syntax for Map declaration:
EDIT
OK here is the Edit:
and if you again want to put more Test objects at key 1 then do as follows: