±âŸ(framework)
2022.05.02 / 13:11

ÀÚ¹Ù Ä÷º¼Ç List, Map, Vector ÀÔ·Â Ãâ·Â

ÄÚÄÚ·Î
Ãßõ ¼ö 195

List ÀÔ·Â

List<String> list = new ArrayList<String>();

list.add("QM6");

list.add("SORRENTO");


List Ãâ·Â(Iterator »ç¿ë)

Iterator<String> it = list.iterator();

while(it.hasNext()) {

String str = (String)it.next();

System.out.println(str);

}


List Ãâ·Â(Çâ»óµÈ for¹®)

for(Object obj : list) {

String str = (String)obj;

System.out.println(str);

}


Map ÀÔ·Â

Map<Integer, String> map = new HashMap<Integer, String>();

map.put(1, "MALIBU");

map.put(2, "SM6");


Map Ãâ·Â(Key)

Iterator<Integer> itKey = map.keySet().iterator();

while(itKey.hasNext()) {

System.out.println(itKey.next());

}


Map Ãâ·Â(Value)

Iterator<String> itValue = map.values().iterator();

while(itValue.hasNext()){

System.out.println(itValue.next());

}


µµ¿ò¹ÞÀº »çÀÌÆ® : http://mainia.tistory.com/2323 [³ìµÎÀ屺 ºí·Î±×]


[Ãß°¡]

Map<String, Object> Çü½Ä Ãâ·Â

Map<String, Object> paramMap = new HashMap<String, Object>();

for(Map.Entry entry : paramMap.entrySet()){

     System.out.println("key: " + entry.getKey() + " | value: " + entry.getValue());

     }


List<Map<String, Object>> Çü½Ä Ãâ·Â

List<Map<String, Object>> resultMap = new ArrayList<Map<String, Object>>();

for(Map<String, Object> map : resultMap){

for(Map.Entry<String, Object> entry:map.entrySet()){

        String key = entry.getKey();

        Object value = entry.getValue();

     System.out.println("key: " + key + " | value: " + value);

}

}


µµ¿ò ¹ÞÀº »çÀÌÆ® : http://stackoverflow.com/questions/36782231/printing-a-java-map-mapstring-object-how

http://stackoverflow.com/questions/5787079/how-to-iterate-a-list-like-listmapstring-object


[Vector Ãâ·Â]

Iterator it = vector.iterator();

while(it.hasNext()) {

System.out.println(it.next());

}


µµ¿ò¹ÞÀº »çÀÌÆ® : https://examples.javacodegeeks.com/core-java/util/vector/vector-iterator-example/



Ãâó: https://devesim.tistory.com/26?category=574758 [µ¥ºê½ÉÀÇ °³¹ßÀÚ ·¹ÆÛ·±½º]