Good evening everyone,
I am currently just a student of Java and am stuck on one part of my assignment. I have a multi-dimension array created from a CSV file. I can get it to print no problem however I need to sort it first according to a specific column.
The array looks like this;
Date------------Open----High----Low-----Close---AdjClose---Volume
2000-09-01___33.05__33.45__32.75__33.38__33.38____45869
2000-09-05___33.95__33.99__33.42__33.80__33.80____55722
there is a lot more but did not want to type them all,
I need to sort this array according to the 'Close' column going from highest to lowest.
I did try a bubble sort (rookie move I know), but all it did was change the values in the Close column from high to low, the rest of the rows remained in place.
Can anyone send a suggestion or send a sample to help me past this problem. Keep in mind that ALL fields are Strings.
I also tried the following:
I created two methods that separate the original array and created two more arrays, one is a Date[] and stores just the first column in a date format and the second array is a float[][] which stores the remaining values as floats.
The float[][] array I can sort using the following,
I can print this one and all the float values arrange properly, but I do not know how to include the dates in the printout.public void sortDataArray(float[][] arr, int colNum) { Arrays.sort(arr, new Comparator<float[]>() { @Override public int compare(float[] val1, float[] val2) { if (val1[columnSort] < val2[columnSort]) { return 1; } else { return -1; } } }); }
I am really hoping someone out there can help me, my assignment is due soon, and this is the second last thing I need to get done.
(last thig is to implement a lambda expression somewhere in my code but I will deal with that after I get this fixed)
Thanks.