webrtc를 사용해서 화상채팅 앱을 만드는 중 HashMap에 저장한 peerConnection 들을 모두 dispose() 해야할 상황이 생겼습니다.. 그래서 entrySet(), keySet() 메소드를 사용해서 dispose()를 할 수 있었습니다. HashMap의 entrySet(), keySet() 예제코드를 포스팅합니다.
entrtSet()은 HashMap에 있는 key와 value 값을 Entry 에 담습니다.
public static void main(String[] args){
Map<Integer, String> map = new HashMap<>();
map.put(1, "일");
map.put(2, "이");
map.put(3, "삼");
for(Map.Entry<Integer,String> entry : map.entrySet()){
System.out.println(entry.getKey()+"="+entry.getValue());
}
}
결과
1=일
2=이
3=삼
keySet() 은 HashMap에 있는 모든 key를 담습니다.
public static void main(String[] args){
Map<Integer, String> map = new HashMap<>();
map.put(1, "일");
map.put(2, "이");
map.put(3, "삼");
for(Integer key : map.keySet()){
System.out.println(key+"="+map.get(key));
}
}
결과
1=일
2=이
3=삼