How to compare equality of lists of arrays with modern Java?

后端 未结 5 1584
清酒与你
清酒与你 2021-01-31 07:18

I have two lists of arrays.

How do I easily compare equality of these with Java 8 and its features, without using external libraries? I am looking for a \"bett

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-31 07:46

    The for loop at least can be streamified, leading to:

    return (list1.size()==list2.size() &&
            IntStream.range(0, list1.size())
                     .allMatch(i -> Arrays.equals(list1.get(i), list2.get(i)));
    

提交回复
热议问题