2021-01-01

package aaa;

import java.util.*;
import java.util.Map.Entry;


public class aaa {

    public static void main(String[] args) {
        List list = new  ArrayList<>();
        list.add(111);
        list.add(222);
        list.add(333);
        for(Integer i :list){
            System.out.println(i);
        }
        for(Iterator it = list.iterator();it.hasNext();){
            Integer temp =it.next();
            System.out.println(temp);
        }
        Iterator it =list.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }
        
        Set set = new HashSet<>();
        set.add("aaa");
        set.add("bbb");
        set.add("ccc");
        for(String i: set){
            System.out.println(i);
        }
        for(Iterator it_set=set.iterator();it_set.hasNext();){
            String temp=it_set.next();
            System.out.println(temp);
        }
        
        Iterator it_set=set.iterator();
        while(it_set.hasNext()){
            System.out.println(it_set.next());
        }
        
        Map map=new HashMap();
        map.put(111, "aaa");
        map.put(222, "bbb");
        map.put(333, "ccc");
        
        Set> entrySet=map.entrySet();//entrySet键值对
        
        for(Iterator> iter = entrySet.iterator();iter.hasNext();){
            Entry temp =iter.next();
            System.out.println(temp.getKey()+"--"+temp.getValue());
            
        }
        Iterator> it_map =entrySet.iterator();
        while(it_map.hasNext()){
            Entry s_map=it_map.next();
            System.out.println(s_map.getKey()+"--"+s_map.getValue());
        }
        
        Set keyset = map.keySet();//keySet键的集合
        
        for(Iterator it_key =keyset.iterator();it_key.hasNext();){
            Integer temp = it_key.next();
            System.out.println(temp+"--"+map.get(temp));
        }
        Iterator it_key = keyset.iterator();
        while(it_key.hasNext()){
            Integer temp =it_key.next();
            System.out.println(temp+"--"+map.get(temp));
        }
        

    }
    
}

你可能感兴趣的:(2021-01-01)