简体   繁体   中英

Java Sorting Multiple List for Excel

I am trying to import an excel document, add and delete some records and then sort the records by there columns before exporting it back to excel. In total there are 20 columns that are import/exported.

I created arraylists to capture the columns information. After processing them I am trying to sort them.

static List<String> rA_column = new ArrayList<String> ();
static List<String> rB_column = new ArrayList<String> ();
static List<String> rC_column = new ArrayList<String> ();

How can I sort them by rC_column first and then rA_column, but still maintain all the records together without accidentally mixing up cells causing the records information to be inaccurate?

I do not understand how I could use map or collect sort for this to work because its limiting me to two strings in map and I have 20 arraylists to keep in sync.

Don't create three different Lists. Instead you could create a class holding all three values and that you can sort by any fields which keeps the records together eg

class ExcelRow {
    String field1;
    String field2;
    String field3;
}

And you would sort it like this Sort ArrayList of custom Objects by property

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM