close

@法國人 Bioderma 貝德瑪淨妍/新舒妍TS 高效潔膚液500ml ~**2000免郵**超取/黑貓宅配 2011-05-27

☆巴黎草莓☆ NATURACTOR 娜拉兒 遮瑕膏 另有 歐達兒 蓋斑膏/資生堂遮瑕蜜 S100 超商取貨 2012-01-12

☆巴黎草莓☆ Schwarzkopf 施華蔻 OSiS 蓬蓬粉 (蓬鬆粉/澎澎粉) 年度下殺$299 可超取 面交 2012-01-12

If the data format is showing as above , and we want to sort these data by time.

We can use the method as below :


First , we should input these data into a String Array , 

then , 


Arrays.sort(buyList, new Comparator()

public int compare(Object o1, Object o2)

try

String o1Str = (String)o1;
String o2Str = (String)o2;
String[] o1StrSplit = o1Str.split(" ");
String[] o2StrSplit = o2Str.split(" ");
SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd",Locale.ENGLISH);
Date d1 = df.parse(o1StrSplit[o1StrSplit.length-1]);
Date d2 = df.parse(o2StrSplit[o2StrSplit.length-1]);
return d1.compareTo(d2); 

}
catch(Exception e)
{

e.printStackTrace();

}
return -1; 

});


arrow
arrow
    全站熱搜

    JerryCheng 發表在 痞客邦 留言(0) 人氣()