같은 id에서 날짜가 가장 큰 대상을 얻습니다

1978 단어
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;

public class Data {

    private String item;
    // private String objType;
    private String time;
    private String time1;

    public Data(String chaine) throws Exception {
    String s[] = chaine.split(" ");
    this.item = s[0];
    // this.objType = s[1];
    this.time = s[1] + " " + s[2];
    }

    public String getTime() {
    return time;
    }

    public String getTime1() {
    return time1;
    }

    public String getKey() {
    return item + " " + item;
    }

    public String toString() {
    return item + " " + time;
    }

    public static void main(String[] args) throws Exception {
    ArrayList<Data> dataList = new ArrayList<Data>();
    dataList.add(new Data("00000ar6n8xlg00b 2012/7/1 23:36:52 "));
    dataList.add(new Data("000i0ar6o6262twu 2012/7/19 20:56:41 2012/8/30 10:30:04"));
    dataList.add(new Data("000i0ar6o7435u08 2012/7/20 10:35:46 2012/8/24 13:15:14"));
    dataList.add(new Data("00000ar6n8xlg00b 2012/7/1 23:36:52 "));
    dataList.add(new Data("000i0ar6o6262twu 2012/8/23 17:14:40 2012/8/24 10:29:54"));
    dataList.add(new Data("000i0ar6o7435u08 2012/7/20 11:37:30 "));
    dataList.add(new Data("00000ar6n8xlg00b 2012/8/29 13:47:02 "));
    dataList.add(new Data("000i0ar6o6262twu 2012/8/29 13:47:02 "));
    dataList.add(new Data("000i0ar6o7435u08 2012/8/29 13:47:02 "));
    Map<String, Data> dataMap = new TreeMap<String, Data>();
    for (Data data : dataList) {
        if (!dataMap.containsKey(data.getKey()))
        dataMap.put(data.getKey(), data);
        else {
        if (data.getTime().compareTo(dataMap.get(data.getKey()).getTime()) > 0) {
            dataMap.put(data.getKey(), data);
        }
        }
    }
    System.out.println(dataMap.values());
    }
}

좋은 웹페이지 즐겨찾기