I'm trying to figure out how I would take the values of an array and pass it to another array. The image at the bottom is the array I was able to boil down to with crimeArrayNumbers
. I am trying to take each index, like index 1 for example, and store it separately in an array held in another class. In this case, the array in another class if newUSCrimeArrays.population
. Ideally, I'm trying to create an array for each column so that I can manipulate them and do math & search operations.
I've done a little research and thought that Arrays.copyOfRange
or System.arraycopy()
might work. However, I am not sure how to implement that properly right now. Is there an easier or more efficient method of doing this?
try {
br = new BufferedReader(new FileReader(newUSCrimes.fileName));
while ((line = br.readLine()) != null && !line.isEmpty()) {
String[] crimesArray = line.split(csvComma);
long[] crimesArrayNumbers = new long[crimesArray.length];
//resting the index inside the main loop
index = 0;
for (int i = 0; i < crimesArrayNumbers.length; i++) {
try {
crimesArrayNumbers[index] = Long.parseLong(crimesArray[i]);
index++;
newUSCrimeArrays.population = Arrays.copyOfRange(crimesArrayNumbers, 0, 0);
} catch (IndexOutOfBoundsException | NumberFormatException ioob) {
}
} //end for loop
crimesArrayNumbers = Arrays.copyOf(crimesArrayNumbers, index);
System.out.println(Arrays.toString(crimesArrayNumbers));
}//end try
System.out.println();
System.out.println(Arrays.toString(newUSCrimeArrays.population));
} catch (FileNotFoundException e) {
} catch (IOException e) {
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
}
}
}