leetcode를 풀면서 필요한 개념과 메서드 위주로 정리함
HashMap<String, Integer> map = new HashMap<>();
for (String player : participant) {
map.put(player, map.getOrDefault(player, 0) + 1);
}
for (String key : map.keySet()) {
if (map.get(key) != 0) {
result = key;
break;
}
}
String answer = "";
Iterator<Map.Entry<String, Integer>> iter = map.entrySet().iterator();
while(iter.hasNext()) {
Map.Entry<String, Integer> entry = iter.next();
if(entry.getValue != 0) {
answer = entry.getKey();
break;
}
}
import java.util.HashMap;
public class MyClass {
public static void main(String[] args) {
HashMap<String,Object> hm = new HashMap<String,Object>();
hm.put("first", "1");
hm.put("second", "4");
System.out.println( hm.containsKey("first") ); // true
System.out.println( hm.containsKey("third") ); // false
}
}