How can I convert a Stream of Strings to Stream of String pairs?

前端 未结 4 1816
说谎
说谎 2021-01-12 20:43

I want to take a stream of strings and turn it into a stream of word pairs. eg:

I have: { \"A\", \"Apple\", \"B\", \"Banana\", \"C\", \"Carrot\" }

4条回答
  •  独厮守ぢ
    2021-01-12 21:00

    Here's a minimal amount of code that creates a List> of the pairs:

    List> pairs = new LinkedList<>();
    testing.reduce((a, b)-> {pairs.add(Arrays.asList(a,b)); return b;});
    

提交回复
热议问题