String、String[]、ArrayList<String>之间的转换

1. ArrayList<String> 转换为 String[]

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

  list.add("aaa");

  list.add("bbb");

  String[] arrString = list.toArray(new String[list.size()]) ;

 

2. String[] 转换为 ArrayList<String>

  ArrayList<String> list = new ArrayList<> (new String[] { "aaa", "bbb" });

 

3. ArrayList<String>  转换为 String

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

  list.add("aaa");

  list.add("bbb");

  String str = String.join(",",  list.toArray(new String[list.size()]));

 

4. String 转换为 ArrayList<String>

  String str ="1,2,3,4,5";

  ArrayList<String> b = new ArrayList( str.split(',') ) ;

 

posted @ 2017-11-21 10:35  子·聪  阅读(28090)  评论(0编辑  收藏  举报