Does Java SE 8 have Pairs or Tuples?

前端 未结 9 862
独厮守ぢ
独厮守ぢ 2020-11-28 18:37

I am playing around with lazy functional operations in Java SE 8, and I want to map an index i to a pair / tuple (i, value[i]), then <

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 19:14

    Since you only care about the indexes, you don't need to map to tuples at all. Why not just write a filter that uses the looks up elements in your array?

         int[] value =  ...
    
    
    IntStream.range(0, value.length)
                .filter(i -> value[i] > 30)  //or whatever filter you want
                .forEach(i -> System.out.println(i));
    

提交回复
热议问题