728x90

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. Map
Map<Object, String> map1 = new HashMap<Object, String>();
    Map1.put("1", "One");
    Map1.put("2", "Two");
    Map1.put("3", "Three");

//2. ArrayList
ArrayList<String> list1 = new ArrayList<String)();
    List1.add("One");
    List2.add("Two");
    List3.add("Three");

//3. HashMap
HashMap<Object, String> map2 = new HashMap<Object, String>();
    Map2.put("1", "One");
    Map2.put("2", "Two");
    Map2.put("3", "Three");


System.out.println("==while문 활용==");

//1
While(it.hasNext()){
    String key = (String)it.next();
    System.out.println(key);
}

//2 
While(it.hasNext()){
    String value = (String)it2.next();
    System.out.println(value);
}

//3
While(it3.hasNext()){
    String value = (String)it3.next();
    System.out.println(value);
}


System.out.println("==for 문 활용==");


//1
For(Object key : map1.keySet()){
    System.out.println("key :" + key + "/value :" + map1.get(key));
}

//2
For(int I = 0 ; list1.size(); i++){
    System.out.println(list1.get(i).toString());
}

//3
For(Object key : map2.keySet()){
    System.out.println("key :" + key + "/value :" + map2.get(key));
}

}
}

+ Recent posts