Hello, I have a simple question.
I am just wondering out of curiosity, which of the following two methods for loading a series of numbers from a text file, converting them to an integer and loading them into an array is the most efficient?
The input file looks like the following:
11111111111111111111
10000000000000000001
10111111001000000001
10100000001111111111
10100011111000000001
10100000001000100001
10100000031000100001
10111111111000100001
10000000000000100021
11111111111111111111
The first method I discovered by accident. When adding a string to a character, the resultant is a string. Method two uses a default char to int method found in the character class.Code:for (int i = 0; i < 10; i++) {
temp = input.nextLine();
for (int j = 0; j < 20; j++) {
// position[i][j] = Integer.parseInt(temp.charAt(j)+""); // <--Method one
position[i][j] = Character.getNumericValue(temp.charAt(j)); // <--Method two
}
}
Or is there some other, more efficient method of loading entire text files whose contents contain only numbers and the number of rows and columns are known (as in above, 10 rows, 20 columns) into a 2-D array of integers?
Thanks in advance =).

