java 8 - Java8 equivalent for ruby's each_with_index -


I wonder if there is some stream operation that can be done in Ruby as every_with_index

Where the is repeated on the value of each_v_index , as well as index of values.

There is no stream operation for that particular purpose, but you can copy the functionality in many ways You can.

Index Variable: The following approach works well for sequential streams.

  int [] index = {0}; Stream.forEach (item -> System.out.printf ("% s% d \ n", item, index [0] ++));  

External walk: The following approach works fine for parallel streams, as long as the original collection is supported by random access.

  List & lt; String & gt; Token = ...; IntStream.range (0, tokens.size ()). For (index -> system out.printf ("% s% d \ n", token .get (index), index);  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -