【java 】数据结构 ArrayList HashMap

 ArrayList

private static void runList2() {
        List list = new ArrayList();
        list.add("java111");
        list.add("java222");
        list.add("java333");
        list.add("java444");
        list.add("java555");
        Iterator it = list.iterator();
        //itit 迭代 for
        while (it.hasNext()) {
            String item =  it.next();
            System.out.println(item);
        }
    }

    private static void runList() {
        List list = new ArrayList();
        list.add("java111");
        list.add("java222");
        list.add("java333");
        list.add("java444");
        list.add("java555");

        // itli list for

        for (int i = 0; i < list.size(); i++) {
            String s =  list.get(i);
            System.out.println(s);
            
        }
    }

 

HashMap 

private static void runMap2() {
    Map map = new HashMap();
    map.put("01","java111");
    map.put("02","java111");
    map.put("03","java111");
    map.put("04","java111");

    Set keySet = map.keySet();
    Iterator it = keySet.iterator();
    //itit 迭代 for
    while (it.hasNext()) {
        String key =  it.next();
        System.out.println(key);
        System.out.println(map.get(key));
    }
}

private static void runMap() {
    Map map = new HashMap();
    map.put("01","java111");
    map.put("02","java111");
    map.put("03","java111");
    map.put("04","java111");

    Set keySet = map.keySet();
    //iter 增强 for
    for (String key : keySet) {
        System.out.println(key);
        System.out.println(map.get(key));
    }
}

 

你可能感兴趣的:(java)