Hello,
I need to link two types of ArrayList <String>. I thought to create a HashMap whose key is the first ArrayList <String> and value the ArrayList <String> corespondent.
Here is my code
Code:
Public HashMapTest() {
klst.add("a");
klst.add("b");
klst.add("c");
vallst.add(""+1);
vallst.add(""+2);
vallst.add(""+3);
keyValue.could(klst, vallst);
klst.clear();
vallst.clear();
klst.add("aa");
klst.add(ba);
klst.add("ca");
vallst.add("1a");
vallst.add("2a");
vallst.add("3a");
keyValue.could(klst, vallst);
klst.clear();
vallst.clear();
ArrayList rst = <String>new ArrayList <String>();
ArrayList <String> rsk =new ArrayList <String>();
rsk.add("aa");
rsk.add(ba);
rsk.add("ca");
rst =(ArrayList <String>)keyValue.get(rsk);
for(int i =0; I <rst.size(); I + +)
{
System.out.System.out.println(rst.get(i));
}
}
I review the console error message:
Code:
java.lang.NullPointerException
At the line of the loop. Apparently, he does not like me as key to the ArrayList, since I created HashMap <String, ArrayList <String>> without any problems. Yet I have seen no indication cons in the java API. Does someone could tell me why my code does not work, or else tell me another way to combine my two types of ArrayList? Thank you very much in advance.
Bookmarks