'자바관련'에 해당되는 글 1건

  1. 2015.09.24 HashTable과 HashMap 순회방법

HashTable 순회 방법

        Hashtable<StringString> hashtable = new Hashtable<StringString>();
        hashtable.put("1""a");
        hashtable.put("2""b");
        hashtable.put("3""c");
        hashtable.put("4""d");
        
        Enumeration<String> enumKey = hashtable.keys();
        
        while(enumKey.hasMoreElements()){
            String key = enumKey.nextElement();
            String value = hashtable.get(key);
            System.out.println(value);
        }    
cs


HashMap 순회방법
        HashMap<StringString> hashmap = new HashMap<StringString>();
        hashmap.put("1""a");
        hashmap.put("2""b");
        hashmap.put("3""c");
        hashmap.put("4""d");
        
        for(Entry<StringString> entry : hashmap.entrySet()){
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + " - " + value);
        }
cs


Posted by slender ankles
,