lambda表达式foreach获取遍历的索引 -09-29

List list = java.util.Arrays.asList("a","b","c");

        Stream.iterate(0, i -> i + 1).limit(list.size()).forEach(i -> {

            System.out.println(String.valueOf(i) + list.get(i));

        });

------------------------------------------------------------------------------------------------------------------

Stream.iterate(0, t -> t + 1).limit(fields.length).forEach(t -> {
    System.out.println(Integer.valueOf(t));
    System.out.println( fields[t]);

你可能感兴趣的:(lambda表达式foreach获取遍历的索引 -09-29)