2020-12-07 JAVA LIST MAP STREAM

public static void main(String[] args) {
        TreeMap 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 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 numbers() {
        return Stream.iterate(0, i -> {
            int result = x + i;
            x = i;
            return result;
        });
    }

    public static  void show(Stream stream) {
        stream
                .limit(3)
                .forEach(System.out::println);
        System.out.println("++++++++");
    }

你可能感兴趣的:(2020-12-07 JAVA LIST MAP STREAM)