Java String[]转List<String>

整理笔记:String [] 转 List<String>

String [] al = new String[]{"1","q","a","z"};

1、最差方案    
List<String> b = new LinkedList<String>();
for(String c:al){
    b.add(c);
}
b.forEach(System.out::println);

2、稍微聪明点的
#import java.util.Arrays;
List<String> listString = Arrays.asList(al); 
listString.forEach(System.out::println);

3、1.8jdk新方法
#import java.util.stream.Collectors;
#import java.util.stream.Stream;
List<String> listStrings = Stream.of(al).collect(Collectors.toList()); 
listStrings.forEach(System.out::println);

 
posted @ 2018-04-02 16:14  currentTimeMillis  阅读(497)  评论(0编辑  收藏  举报