반응형 HashMap2 Java HashMap의 자주 사용되는 메소드 HashMap은 카운터가 필요할 때 매우 유용합니다. HashMap countMap = new HashMap(); //.... a lot of a's like the following if(countMap.keySet().contains(a)){ countMap.put(a, countMap.get(a)+1); }else{ countMap.put(a, 1); } 1. HashMap을 통한 루프 Iterator it = mp.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry)it.next(); System.out.println(pairs.getKey() + " = " + pairs.getValue()); }Map map = .. 2017. 11. 22. [JAVA] Iterator, for문 map,list,hashmap 기본활용방법 Iterator, for문 map,list,hashmap 기본활용방법 iterator에 대해서 궁금해서 찾아봤는데 반복자라는 뜻이며 for문보다 간단히 활용할수 있을것 같아for문과 함께 비교해서 사용을 아래와 같이 해보았다. import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.Map; public class foreach { public static void main(String[] args) {//1. MapMap map1 = new HashMap();map1.put("1", "One");map1.put("2", "Two");map1.put("3", "Three");//2. Array.. 2017. 10. 10. 이전 1 다음 반응형