1、以空格方式分割字符串
str = "Hello I come from china";
String[] splited = str.split("\\s+");
2、字符串數組轉換爲List:
實現方式一:使用Stream中的Collector收集器
String[] arrays = new String[]{"a", "b", "c"};
List<String> listStrings = Stream.of(arrays).collector(Collectors.toList());
實現方式二:使用java.util.Arrays工具類中的asList()方法
String[] arrays = new String[]{"a", "b", "c"};
List<String> listStrings = Arrays.asList(arrays);
3、List 轉換爲數組
實現方式一: 使用Stream 方式
String[] ss = listStrings.stream().toArray(String[]::new);
實現方式二:使用List中的toArray()方法
String[] sss = listStrings.toArray(new String[listStrings.size()]);