Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- pseudo-code
- @NoArgsConstructor
- ajax
- MariaDB Query Log
- interrupted()
- select
- this
- 마리아DB 쿼리 로그
- json
- this와 this() 차이
- function test
- 구간합
- Bean LifecCycle
- Java
- 2차원배열 구간합
- 자바 람다식
- 상속과 참조
- 백준 1235번
- 합배열
- 생성자
- 백준
- 슈더코드
- jquery
- 구간합구하기
- @AllArgsConstructor
- SQL
- InterruptException
- 백준 11659번
- map()
- 백준 11660번
Archives
- Today
- Total
평범한 연구소
[JAVA] HashMap 을 value로 정렬하기 본문
public static int[] twoSum(int[] nums, int target) {
int[] result = null;
Map<Integer, Integer> map = new HashMap<>();
for(int i=0; i<nums.length; i++) {
map.put(i, nums[i]);
}
// Map을 value로 정렬
List<Map.Entry<Integer, Integer>> list = new LinkedList<>(map.entrySet());
list.sort(new Comparator<Map.Entry<Integer, Integer>>() {
@Override
public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer>o2) {
return o1.getValue() - o2.getValue();
}
});
}
}
'JAVA > 기본 개념' 카테고리의 다른 글
JAVA 생성자, 디폴트 생성자, 생성자 오버로딩 (0) | 2025.03.06 |
---|---|
[JAVA] Map<E,K> - HashMap, LinkedHashMap, Hashtable, TreeMap, Properties (0) | 2022.08.06 |
[JAVA] Set - HashSet, LinkedHastSet, TreeSet (0) | 2022.08.06 |
[JAVA] 리스트 List - ArrayList, LinkedList, Vector (0) | 2022.08.03 |
[JAVA] 제네릭 generic (0) | 2022.08.03 |