0

I have a list of Record,

List<Record> records = new ArrayList<>();

I want to output the content of records into a CSV file with 3 columns, but want the rows in the output order of cid, as below:

  cid     cname    spu
  001     Book     23a
  001     Book     24a
  001     Book     13c
  002     Music    2f
  002     Music    24g
  002     Music    24a

...

The order of row 001 and 002 in the list are mixed, so they are not ordered. I need to output them to a file:

BufferedWriter br = new BufferedWriter("file.txt");
  for(Record record : records){
      writer.write(record)
   }

How to achieve this?

class Record{

    protected String cid;
    protected String cname;
    protected String spu;

    public Record(String cid, String cname, String spu) {

        this.cid = cid;
        this.cname = cname;
        this.spu = spu;
    }
}
marlon
  • 6,029
  • 8
  • 42
  • 76

0 Answers0