Q:

java access hashmap internal array by index

I have a Map.Entry<File, int[]> of the form:
/data/train/politics/p_0.txt, [0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]
/data/train/science/s_0.txt, [1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0]
/data/train/atheism/a_0.txt, [0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
/data/train/sports/s_1.txt, [0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1]

I want to put this data to a 2D array of the form:
double[][] features = new double[ GLOBO_DICT.size() ][ perceptron_input.size() ];

But I don't want that file name (label) to be included in the 2D array. 
I was thinking something like the following would do the trick but now I'm not so certain. 
 //number of features, number of x, y, z
 int size_of_globo_dict = GLOBO_DICT.size();

 //number of instances
 int NUM_INSTANCES = perceptron_input.size();

double[][] features = new double[ perceptron_input.size() ][ GLOBO_DICT.size() ];

for(int i = 0; i <= size_of_globo_dict; i++)
{
    for(int j = 0; j <= NUM_INSTANCES; j++)
    {
       features[j][i] = 
    }
}

I need to be able to access the internal int array by it's index, how to do that?
something like 'internatl_int_array.get( instance i)'

A:

A simple way would be to iterate over the HashMap using a for each loop like:
for(Entry<File, int[]> entry : myMap.entrySet())

For every entry, take the value (the int array) and store it in the matrix.
When you go to the next entry, just increment the line index (i in your case) for the matrix.
Here is an example, just adapt it to your problem:
Map<String,int[]> myMap = new HashMap();

int []x = {1,2,3,4};
int []y = {5,6,7,8};
int []z = {9,2,3,4};

myMap.put("X",x);
myMap.put("Y",y);
myMap.put("Z", z);

int i = 0;
int [][]matrix = new int[10][10];

for(Entry<String, int[]> entry : myMap.entrySet()){

    int []a =entry.getValue();

    for(int j = 0; j < a.length; j++){

        matrix[i][j] = a[j];
    }
    i++;
}

I used String as Key type, since we don't care about the key, only about the value. Iterate the hashmap, get the value (the int array) and copy those values into the matrix. Every entry represents a new line in the matrix.

