@Test
public void ArrayToOthers() throws Exception {
int[] arrInt = {1, 2, 3, 4};
// ArrrayInt数组转化为字符串
String intStr = Arrays.stream(arrInt).boxed().map(item -> item.toString()).collect(Collectors.joining(","));
System.out.println("ArrrayInt数组转化为字符串 = " + intStr);
// ArrrayInt数组转化为List集合
List<Integer> arrayIntToList = Arrays.stream(arrInt).boxed().collect(Collectors.toList());
System.out.println("ArrrayInt数组转化为List集合 = " + arrayIntToList);
/***********************************************************************************************************************************/
String[] arrStr = {"apple", "banana", "per"};
String strStr = Arrays.stream(arrStr).collect(Collectors.joining(","));
System.out.println("ArrrayStr数组转化为字符串 = " + strStr);
List<String> arrayStrToList = Arrays.stream(arrStr).collect(Collectors.toList());
System.out.println("ArrrayStr数组转化为List集合 = " + arrayStrToList);
}
Java8-数组转其它格式
于 2021-01-17 18:01:59 首次发布