Posted on 2012-02-20 15:00
yuhaibo736 阅读(6123)
评论(0) 编辑 收藏
数组、List<-->Set、数组<-->Set、Map-->Set、Map-->List】"
trackback:ping="http://www.blogjava.net/yuhaibo736/services/trackbacks/370348.aspx" />
-->
- public class TestApp {
-
- public static void main(String[] args) {
-
- List<String> list = new ArrayList<String>();
- list.add("蹇伟");
- list.add("Jerval");
- list.add("杰威");
- Object[] objects = list.toArray();
- System.out.println("objects:"+Arrays.toString(objects));
- String[] strings1 = new String[list.size()];
- list.toArray(strings1);
- System.out.println("strings1:"+Arrays.toString(strings1));
- String[] strings2 = list.toArray(new String[0]);
- System.out.println("strings2:"+Arrays.toString(strings2));
-
- String[] ss = {"JJ","KK"};
- List<String> list1 = Arrays.asList(ss);
- List<String> list2 = Arrays.asList("AAA","BBB");
- System.out.println(list1);
- System.out.println(list2);
-
- List<String> list3 = new ArrayList<String>(new HashSet<String>());
-
- Set<String> set = new HashSet<String>(new ArrayList<String>());
-
- String[] strs = {"AA","BB"};
- Set<String> set2 = new HashSet<String>(Arrays.asList(strs));
- System.out.println(set2);
-
- Set<String> set3 = new HashSet<String>(Arrays.asList("PP","OO"));
- String[] strSet = new String[set3.size()];
- set3.toArray(strSet);
- System.out.println(Arrays.toString(strSet));
-
- Map<String, String> map = new HashMap<String, String>();
- map.put("YYY", "UUU");
- map.put("RRR", "TTT");
-
- Set<String> mapKeySet = map.keySet();
-
- Set<String> mapValuesSet = new HashSet<String>(map.values());
-
- List<String> mapValuesList = new ArrayList<String>(map.values());
-
- }
- }