java - How to read and sort data that's only separated by spaces? -


i have data set wanted read out , sort arrays, problem of data separated spaces only.

i wanted use loops sort data big multi-dimensional array, since it's separated spaces i'm @ complete loss.

the data sorted year followed 6 spaces, month followed three, 31 sets of data month, each of followed 3 spaces. so:

1974      1   0.00   0.01 

i'd wanted this:

while(year)     //sort annual array         while(month)             //sort monthly array                 for(each individual data entry)                     //sort each data entry each month's array 

sorry if wording isn't here. many in advance.

probably best create class data, write sort custom comparator.

you should use scanner read in data data class, , store in list

public class mydata{     date date;     float data[]; } list<mydata> data = new arraylist<mydata>(); /// add data  collections.sort(data, new comparator<mydata>(){     @override     public int compare(mydata data1, mydata data2) {         // compare on year     } }); // copy new list  collections.sort(data, new comparator<mydata>(){     @override     public int compare(mydata data1, mydata data2) {         // compare on month     } }); /// keep sorting , copying 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -