반응형

Fast Reference                                 ▼▼▼


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/


Fast Reference                                 ▲▲▲



반응형

+ Recent posts