I have an integer Array and a String, the string has characters P and N, I want to map the elements of the string with it's respective integer element. eg int array= 1,2,3,4,5 and string has PPNPN P->1,P->2,N->3,P->4,N->5.
int array[]={1,2,3,4,5};
String s1="PPNPN";
String []array1=new String[s1.length()];
for(int i = 0; i < s1.length(); i++)
{
array1[i] = String.valueOf(s1.charAt(i));
}
Map <String,Integer> map1=new HashMap<String,Integer>();
for(int i=0;i<array1.length;i++)
{
map1.put(array1[i],array[i]);
}
for (String key : map1.keySet())
{
System.out.println(key + " " + map1.get(key));
}
It is not printing all the values.
Map<String, List<Integer>>or similar in order to store a bunch of values with a single keyMapinterface first.