java8 stream lambda 数组 集合以特殊字符 转字符串

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4};
        String str1 = Arrays.stream(arr).boxed().map(i -> i.toString()).collect(Collectors.joining(","));
        System.out.println(str1);

        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        String str2 = list.stream().collect(Collectors.joining(","));
        System.out.println(str2);

        List<Integer> listInt = new ArrayList<>();
        listInt.add(1);
        listInt.add(2);
        listInt.add(3);
        listInt.add(4);
        String str3 = listInt.stream().map(r -> r.toString()).collect(Collectors.joining(","));
        System.out.println(str3);
    }

 

    原文作者:henry_韩
    原文地址: https://blog.csdn.net/hanwenyi520/article/details/89946230
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞