Arrays obtained from DB are often uncertain. I wondered if it would be possible to express such an array match check with as little code as possible. I want to do it neatly, so the situation should be as follows
Simple types such as String and Integer can be sorted by Stream.sorted ()
.
However, this is not the case.
Also, there is no problem if you define a Comparator.
NullPointerException.
Needless to say here
Sample.java
public boolean isEqualsList(List<?> a, List<?> b){
return Arrays.equals(a.stream().sorted().toArray(), b.stream().sorted().toArray());
}
Even if you define a Comparator, it seems to be just barely neat.
Sample.java
public boolean isEqualsList(Comparator comp, List<?> a, List<?> b){
return Arrays.equals(a.stream().sorted(comp).toArray(), b.stream().sorted(comp).toArray());
}
I was able to write in one sentence. It's unpleasant that toArray () is Object [], but it's just a match check, so there's no problem.