将List<String> 通过 toArray(new String[0]) 转成一个String[]
java数组转List
List<String> b = Arrays.asList("a", "b", "b", "c", "c"); 这种写法构建一个类
//准备一个String数组
String[] strs = {"aa","bb","cc"};
//String数组转List
List<String> strsToList1= Arrays.asList(strs);
for(String s:strsToList1){
System.out.println(s);
}
File[] 数组不能使用jdk新特性,只能转化为List后才能使用
Arrays.stream(array[]).forEach(record ->{});
File[] fileArray= file.listFiles();
Arrays.stream(fileArray).forEach(record ->{
readFile(record.getPath());
});
构建List的简单方法
Book book = new Book();
book.setName("aaa");
List<Book> bookList = Collections.singletonList(book);
bookList.stream().forEach(item->{
System.out.println("book = "+item.getName());
});