Language/JAVA

List 객체 정렬

Sinnak86 2017. 9. 5. 10:14

Collections 를 사용하여 List 안에 객체를 정렬한다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
 
    //...클래스 선언 및 등등 작업
 
        List<Map<String, Object>> result = pcDao.getList(map);
 
        //해당 기능 오름차순
        Collections.sort(result, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> b1, Map<String, Object> b2) {
                return (Integer.parseInt(b1.get("statue").toString()) < Integer.parseInt(b2.get("statue").toString())) ? -1 : (Integer.parseInt(b1.get("statue").toString()) > Integer.parseInt(b2.get("statue").toString())) ? 1 : 0;
            }
        });
cs