Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<LogEntryComparator> entries = new LinkedList<LogEntryComparator>();
- Date date = null;
- for (String line : list) { //list is an arraylist of strings.
- String time = "2011 " + line.substring(0, 15);
- try {
- date = FORMAT.parse(time);
- } catch (Exception e) {
- e.printStackTrace();
- }
- entries.add(new LogEntryComparator(date, line.substring(15)));
- }
- Collections.sort(entries);
- ...
- import java.util.Date;
- public class LogEntryComparator implements Comparable<LogEntryComparator> {
- Date time = null;
- String entry = "";
- public LogEntryComparator(Date date, String entry) {
- this.time = date;
- this.entry = entry;
- }
- @Override
- public int compareTo(LogEntryComparator le1) {
- return time.compareTo(le1.time);
- }
- }
- result (as you can see unsorted)
- Sun Jul 31 17:09:50 CEST 2011 <phl0w> tes
- Sun Jul 31 17:10:49 CEST 2011 <Andy_> Speed
- Sun Jul 31 17:10:51 CEST 2011 <Andy_> lol Speed
- Sun Jul 31 19:20:50 CEST 2011 <phl0w> lolfile1
- Fri Jul 29 17:09:50 CEST 2011 <phl0w> tes
- Sun Jul 31 17:08:49 CEST 2011 <Andy_> Speed
- Sun Jul 31 17:11:51 CEST 2011 <Andy_> lol Speed
- Sun Jul 31 19:20:53 CEST 2011 <phl0w> lolfile3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement