List,Set,Map,数组之间的相互转换

来源:互联网 发布:邮件群发软件免费版 编辑:程序博客网 时间:2024/04/28 22:04

1.将Array转化为List

String[] words = {"ace","boom","crew","dog","eon"};

List<String> wordList = Arrays.asList(words);

2.将List转为Array

List<String> worldMessage = new ArrayList<String>();

String []strArray = worldMessage.toArray(new String[len]);

3.将List转化为Set

List<String> list = new ArrayList<String>();

Set<String> set = new HashSet<String>(list);

4.将Set转为List

Set<String> set = new HashSet<String>();

List<String> list = new ArrayList<String>(set);


 查看API文档,实现List,set接口的类的构造方法就明白了!


 

0 0
原创粉丝点击