Let's start with the following lists :
List<Double> firstList = new ArrayList<>();
firstList.add(2.0);
firstList.add(3.0);
List<Double> secondList = new ArrayList<>();
secondList .add(2.0000000001);
secondList .add(2.99999999994);
I know I can compare each element one by one using brute force. Of course, I already checked that both lists have the same number of elements.
boolean isEqual = true;
for (int i = 0; i < firstList.size(); i++) {
isEqual &= Math.abs(firstList.get(i) - secondList.get(i)) < 1.0e-6;
}
return isEqual;
My question : is there a way to compare these two lists of double values using lambda expressions? It seems to be easy with any other type of objects, but not with doubles. I need to check if the two lists are numerically equal.
Thanks in advance.