2020-12-07 JAVA LIST MAP STREAM

public static void main(String[] args) {
        TreeMap<String,String> map = new TreeMap<>();
        map.put("bizContent","bizContent.toString()");
        map.put("appId",Configs.APPID.toString());
        map.put("timestamp","timestamp.toString()");
        map.put("serviceName","serviceName");
        map.put("key",Configs.key);
        final String s = new Gson().toJson(map);

        Map<String,String> map2 = new HashMap<>();
        map2.put("bizContent","bizContent.toString()");
        map2.put("appId",Configs.APPID.toString());
        map2.put("timestamp","timestamp.toString()");
        map2.put("serviceName","serviceName");
        map2.put("key",Configs.key);


        map2.entrySet().stream()
                .map(e -> e.getKey() + ": " + e.getValue())
                .forEach(System.out::println);

        String collect = map.entrySet().stream()
                .map(e -> e.getKey() + "=" + e.getValue())
                .collect(Collectors.joining("&"));
        System.out.println(collect);
        String collect2 = map2.entrySet().stream()
                .map(e -> e.getKey() + "=" + e.getValue())
                .collect(Collectors.joining("&"));
        System.out.println(collect2);

        Stream.of("i am ben".split(" ")).forEach((i)-> System.out.print(i+" " ));
        //System.out.println("S="+s);

        Random rand = new Random(47);
        show(rand.ints(2).boxed());
        show(rand.ints(10).boxed());

        new RequestModel().numbers().limit(10)
                .map(k->  k+"=" )
                .forEach((i)-> System.out.print(i+" " ));
        System.out.println();
        rands().limit(SZ)
                .forEach(n -> System.out.format("%d ", n));
        System.out.println();
        rands().limit(SZ)
                .parallel()
                .forEach(n -> System.out.format("%d ", n));
        System.out.println();
        rands().limit(SZ)
                .parallel()
                .forEachOrdered(n -> System.out.format("%d ", n));
    }
    static final int SZ = 14;
    private static int[] rints = new Random(47).ints(0, 1000).limit(100).toArray();
    public static IntStream rands() {
        return Arrays.stream(rints);
    }

    int x = 1;

    Stream<Integer> numbers() {
        return Stream.iterate(0, i -> {
            int result = x + i;
            x = i;
            return result;
        });
    }

    public static <T> void show(Stream<T> stream) {
        stream
                .limit(3)
                .forEach(System.out::println);
        System.out.println("++++++++");
    }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容