List、Set、Map、数组之间各种转换
刚学Java不久的时候,接到一个电面,然后问了一些java的知识,比如说Java的编码,Unicode等,但是最让我蛋疼的是怎么吗map转为set,那个时候对集合用的很少,对集合不是特别了解,map还知道,set就蒙了,然后转为set更蒙了,觉得应该有API提供吧,但是不知道怎么说。后来我一直下来再查这个问题,查到了,但是没有实践过,今天我就来一发代码。 List转Set Set set = new HashSet(new ArrayList()); Set转List List list = new ArrayList(new HashSet()); 数组转为List List arr = Arrays.asList("1", "2", "3"); //或者 String[] arr = {"1", "2"}; List list = Arrays.asList(arr); 数组转为Set int[] arr = { 1, 2, 3 }; Set set = new HashSet(Arrays.asList(arr)); Map的值转化为List List list = new Ar...






















