I have written a program which gives me three arrays.A string array and two dole arrays.... But I want to save them in one thing(I don\'t know if it would be an array or matrix)
public static void main(String[] args) throws Exception {
Map> theMap = new HashMap>();
String [] fruits = {"Apple","Pear","Lemon"};
Double [] firstDArray = {1.1,2.2,3.3};
Double [] secondDArray = {11.11,22.22,33.33};
for(int i = 0; i < fruits.length; i++){
List innerList = new ArrayList();
innerList.add(firstDArray[i]);
innerList.add(secondDArray[i]);
theMap.put(fruits[i], innerList);
}
for(Entry> en : theMap.entrySet()){
System.out.print(en.getKey() + " : ");
for(Double d : en.getValue()){
System.out.print(d + " ");
}
System.out.println();
}
}
In my example, I use a map corresponding to a list of numbers (doubles). The key to the map (string) is the string from the first array, and the list contains the numbers corresponding to the string from each other array. The above example gave me the output:
Pear : 2.2 22.22
Lemon : 3.3 33.33
Apple : 1.1 11.11