从java

时间:2017-10-01 05:36:10

标签: java sorting arraylist

我正在使用比较器方法,并试图找出如何显示我已排序的字段。我需要按姓氏显示的ArrayList(记录)中的三个字段。

private static void sortRecordsOnLastName()
   {
      Collections.sort(records, Record.LastNameComparator());

   }
    static Comparator<Record> LastNameComparator() {
        return (Record o1, Record o2) -> o1.LastName.compareTo(o2.LastName);
    }

该文件是.csv文件,我的代码将其放入ArrayList中。我不理解return语句的作用,因为没有显示。 编辑:我有一个显示器,但只显示[]。

private static void sortRecordsOnLastName() {
    Collections.sort(records, Record.LastNameComparator());
    System.out.println(records);

}

FileReader reader;
       try
       {
           reader = new FileReader(fileName);   
           BufferedReader bReader = new BufferedReader(reader);
           String commaString = null;  // blank at the beginning

           // Reads a complete line
           commaString = bReader.readLine();  

           // If not last line, add to the record
           while((commaString = bReader.readLine())!=null) {
               Record.add(new Record(commaString));
       }

0 个答案:

没有答案