- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
List<Record> getNewestRecords( int maxResults ) {
List<TenantIssue> allRecords = recordsDao.getAllRecords();
if ( allRecords.size() > maxResults ) {
Collections.sort( allRecords, new Comparator() {
public int compare( Record r1, Record r2 ) {
return (int) r1.getDate().getTime() - r2.getDate().getTime();
}
} );
Collections.reverse( allRecords );
List<Record> newestRecords = new ArrayList<Record>();
for ( int i = 0; i < maxResults; i++ ) {
newestRecords.add( allRecords.get( i ) );
}
} else {
return allRecords;
}
return allRecords;
}
exit (_NEVER_MIND_);
}
System.exit(_NEVER_MIND_)
fixed
Collections.sort() и Comparator осилили, а вот про subList не слышали, и бездумное копирование в цикле, конечно, не прибавят скорости.
Good job!