중복제거
List<String> as = new ArrayList<String>(); //중복키구분용 리스트
List<Map<String,Object>> asd = new ArrayList<Map<String,Object>>(); // 원본값들어있는리스트
List<Map<String,Object>> asd2 = new ArrayList<Map<String,Object>>(); // 중복제거된값이들어갈리스트
for(Map<String,Object> m : asd) {
String a = (String)m.get("key3");
if(!as.contains(a)) {
as.add(a);
asd2.add(m);
}
}
Set<Map<String, String>> set = new HashSet<Map<String, String>>(list);
List<Map<String, String>> list2 = new ArrayList<Map<String, String>>(set);
정렬
//lambda + List.sort
list.sort((o1,o2)->{
String date1 = o1.get("eventTime");
String date2 = o2.get("eventTime");
return date1.compareTo(date2);
)};
// 이름(String) 오름차순
Collections.sort(list, new Comparator<HashMap<String, Object>>() {
@Override
public int compare(HashMap<String, Object> o1, HashMap<String, Object> o2) {
String name1 = (String) o1.get("name");
String name2 = (String) o2.get("name");
return name1.compareTo(name2);
}
});
// 나이(Integer) 내림차순
Collections.sort(list, new Comparator<HashMap<String, Object>>() {
@Override
public int compare(HashMap<String, Object> o1, HashMap<String, Object> o2) {
Integer age1 = (Integer) o1.get("age");
Integer age2 = (Integer) o2.get("age");
return age2.compareTo(age1);
}
});
// 점수(Double) 오름차순
Collections.sort(list, new Comparator<HashMap<String, Object>>() {
@Override
public int compare(HashMap<String, Object> o1, HashMap<String, Object> o2) {
Double score1 = (Double) o1.get("score");
Double score2 = (Double) o2.get("score");
return score1.compareTo(score2);
}
});