首页 > 解决方案 > 如何打印出整数流

问题描述

请问,我怎样才能使下面的代码打印出数字而不是打印位置?

    public static void main(String[] args) {
    List<Integer> list1 = Arrays.asList(1, 2, 3, 4, 5);
    List<Integer> list2 = Arrays.asList(1, 2, 3);

    List<int[]> pairs = list1.stream()
            .flatMap(l1 -> list2.stream()
                    .map(l2 -> new int[]{l1, l2}))
            .collect(toList());
    pairs.forEach(System.out::println);
}

输出

[[I@3b6eb2ec, [I@1e643faf, [I@6e8dacdf, [I@7a79be86, [I@34ce8af7, [I@b684286, [I@880ec60, [I@3f3afe78, [I@7f63425a, [I@36d64342 , [I@39ba5a14, [I@511baa65, [I@340f438e, [I@30c7da1e, [I@5b464ce8]

标签: javaarraylist

解决方案


推荐阅读