티스토리 뷰
keySet()
returns a set of the keys in HashTable.
Example Code I
import java.util.*;
public class Main {
public static void main(String[] args) {
Map<Integer, String> hash = new HashMap<>();
String[] fruit = {"apple", "banana", "cherry"};
for (int i = 0; i < fruit.length ; i++) {
hash.put(i,fruit[i]);
}
System.out.println(hash); //{0=apple, 1=banana, 2=cherry}
System.out.println(hash.keySet());//[0, 1, 2]
}
}
|
Example Code II
import java.util.*;
public class Main {
public static void main(String[] args) {
String[] fruit = {"apple", "banana", "cherry"};
String[] fruit2 = {"apple", "cherry"};
Map<String, Integer> hash = new HashMap<>();
for (String arg : fruit) hash.put(arg, hash.getOrDefault(arg, 0) + 1);
for (String arg : fruit2) hash.put(arg, hash.get(arg) - 1);
for (String key : hash.keySet()) {
if (hash.get(key) != 0) System.out.println(key);
}
}
}
|
'JAVA' 카테고리의 다른 글
Arrays.sort in Java (0) | 2019.07.23 |
---|---|
Collection framework - HashMap (0) | 2019.07.23 |
Map - getOrDefault(), putIfAbsent() in Java (0) | 2019.07.23 |
Java IOException - Stream Closed (0) | 2019.07.19 |
Error: could not find or load main class Main (0) | 2019.07.19 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- easy javascript algorithm
- equals()
- algorithm
- math.abs
- 프로그래머스 알고리즘
- code refactoring
- math.max
- rest parameter
- HashMap
- 프로그래머스
- hackerrank solution
- easy algorithm
- Collection Framework
- compareTo()
- substring()
- HackerRank Algorithm
- Javascript Algorithm
- javascript
- 알고리즘
- hackerrank
- C++
- hackerrank javascript
- java
- ... in Javascript
- Object type casting
- 프로그래머스 알고리즘문제
- repeat()
- hackerrank javascript solution
- spring boot application
- string class in java
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
글 보관함