The input my program gets are a few strings of characters which represents rows in a matrix. I would like to put the columns of this matrix in a LinkedHashMap, but without first storing everything in an array and then construct the columns and put them in the LinkedHashMap. The idea is that this should be done as fast as possible.
Example:
Input:
abfad
grgaa
rtwag
The strings that should be saved in a LinkedHashMap are:
agr
brt
fgw
aaa
dag
Edit:
This is how my program does it right now:
String[][] array = new String[n][m];
LinkedHashMap<Integer, String> map = new LinkedHashMap<Integer, String>();
for (int i = 0; i < n; i++) {
array[i] = br.readLine().split("");
}
for (int i = 0; i < m; i++) {
String column = "";
for (int j = 0; j < n; j++) {
column += array[j][i];
}
map.put(i, column);
}