How to compare two Streams in Java 8

后端 未结 6 1836
眼角桃花
眼角桃花 2020-12-03 06:38

What would be a good way to compare two Stream instances in Java 8 and find out whether they have the same elements, specifically for purposes of unit testing?<

6条回答
  •  伪装坚强ぢ
    2020-12-03 07:28

    Using the elementsEqual method in the Guava library:

    Iterators.elementsEqual(s1.iterator(), s2.iterator())
    

提交回复
热议问题