Map,list,set,集合转化

public class TestDemo {
    public static void main(String[] args) {
        // set 转list
        List list = new ArrayList(new HashSet());
        // list 转set
        Set set = new HashSet(new ArrayList());
        // 数组转list
        List stooges = Arrays.asList("Larry", "Moe", "Curly");
        // 数组转set
        int[] a = { 1, 2, 3 };
        Set sets = new HashSet(Arrays.asList(a));
        // map的操作
        Map map = new HashMap();
        map.put("1", "a");
        map.put('2', 'b');
        map.put('3', 'c');
        for(Object ma : map.keySet()){
            System.out.printf("ma:"+ma);
        }
        System.out.println(map);
        System.out.println(map.keySet());
        System.out.println(map.values());
        // 将map转为list
        List mapList = new ArrayList(map.values());
        System.out.println(mapList);
        // 将map的值转化为Set
        Set mapSet = new HashSet(map.values());
        System.out.println(mapSet);
        // list转数组
        List listCon = Arrays.asList("a", "b");
        System.out.println(listCon);
        String[] arr = (String[]) list.toArray(new String[list.size()]);
        System.out.println(Arrays.toString(arr));
    }
}

posted @ 2014-06-27 11:30  love_you_girl  阅读(250)  评论(0编辑  收藏  举报