메뉴 건너뛰기

Cloudera, BigData, Semantic IoT, Hadoop, NoSQL

Cloudera CDH/CDP 및 Hadoop EcoSystem, Semantic IoT등의 개발/운영 기술을 정리합니다. gooper@gooper.com로 문의 주세요.


1. 정렬 수행

        // data를 담고 있는 List변수

List<Map<String, String>> list = new ArrayList<Map<String, String>>();

        // List에 담기는 Map변수

HashMap<String,String> row = new HashMap<String, String>;


// 정렬실행

Collections.sort(list, new MapStringComparator("rest_type"));

Collections.sort(list, new MapStringComparator("corner_id"));

Collections.sort(list, new MapFloatComparator("cnt"));


2. 정렬 클래스(문자열)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class MapStringComparator implements Comparator<Map<String, String>> {
        private final String key;
         
        public MapStringComparator(String key) {
            this.key = key;
        }
         
        @Override
        public int compare(Map<String, String> first, Map<String, String> second) {
            String firstValue =first.get(key);
            String secondValue = second.get(key);
             
             // 내림차순 정렬
             return firstValue.compareTo(secondValue);
        }
    }


3. 정렬 클래스(숫자)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class MapFloatComparator implements Comparator<Map<String, String>> {
        private final String key;
         
        public MapFloatComparator(String key) {
            this.key = key;
        }
         
        @Override
        public int compare(Map<String, String> first, Map<String, String> second) {
            float firstValue = Float.valueOf(first.get(key));
             float secondValue = Float.valueOf(second.get(key));
              
            // 내림차순 정렬
             if (firstValue > secondValue) {
                 return -1;
             } else if (firstValue < secondValue) {
                 return 1;
             } else /* if (firstValue == secondValue) */ {
                 return 0;
             }
        }
    }


번호 제목 날짜 조회 수
33 [gson]mongodb의 api를 이용하여 데이타를 가져올때 "com.google.gson.stream.MalformedJsonException: Unterminated object at line..." 오류발생시 조치사항 2017.12.11 6087
32 lagom-windows용 build.sbt파일 내용 2017.10.12 1334
31 lagom-linux용 build.sbt파일 내용 2017.10.12 2644
30 lagom의 online-auction-java프로젝트 실행시 "Could not find Cassandra contact points, due to: ServiceLocator is not bound" 경고 발생시 조치사항 2017.10.12 1265
29 python3.5에서 numpy버젼에 따른 문제점을 조치하는 방법및 pymysql import할때 오류 발생시 조치사항 2017.09.28 1726
28 python test.py실행시 "ImportError: No module named pyspark" 혹은 "ImportError: No module named py4j.protocol"등의 오류 발생시 조치사항 2017.07.04 3021
27 [Jsoup]특정페이지를 jsoup을 이용하여 파싱하는 샘플소스 2017.04.18 2188
26 [jsoup]Jsoup Tutorial 2017.04.11 1321
25 [메모리 덤프파일 분석] 2017.03.31 1010
24 [springframework]Caused by: org.mariadb.jdbc.internal.util.dao.QueryException: Could not read resultset: unexpected end of stream, read 0 bytes from 4 오류 발생시 조치사항 2017.01.23 1883
23 [tomcat] logrotate를 이용하여 catalina.out로그파일 일별로 로테이션 저장하기 file 2017.01.18 1930
22 List<Map<String, String>>형태의 데이타에서 중복제거 하는 방법 2016.12.23 3513
21 Class.forName을 이용한 메서드 호출 샘플소스 2016.12.21 2389
» Collections.sort를 이용한 List<Map<String, String>>형태의 데이타 정렬 소스 2016.12.15 1888
19 Collections.sort를 이용한 List<User>형태의 데이타 정렬(숫자, 문자에 대해서 각각 asc/desc및 복합정렬) 2016.12.15 1666
18 Eclipse실행시 Java was started but returned exit code=1이라는 오류가 발생할때 조치방법 2016.11.07 1843
17 java스레드 덤프 분석하기 file 2016.11.03 961
16 mybatis와 spring을 org.apache.commons.dbcp2.BasicDataSource의 DataSource로 연동할때 DB설정(참고) 2016.10.31 2606
15 Caused by: java.sql.SQLNonTransientConnectionException: Could not read resultset: unexpected end of stream, read 0 bytes from 4 오류시 확인/조치할 내용 2016.10.31 5346
14 VisualVM 1.3.9을 이용한 JVM 모니터링 file 2016.10.27 1928
위로