I have
Array<Array<Array<CustomObject>>>
and I need to eliminate the duplicates of
Array<Array<CustomObject>>
The order in the arrays doesn't matter, so I don't compare by the index, I compare the elements inside the arrays. The final result needs to keep the 3D array format. So I don't need to flatten the arrays into only one big array.
One way that I thought it might help, was by sorting the arrays. I got to sort the arrays like this:
the most nested (1D) array (
Array<CustomObject>
) -> alphabetically by namethe next (2D) array (
Array<Array<CustomObject>>
) -> alphabetically but just by the first element of the most nested (1D) array (Array<CustomObject>
)- the outer most (3D) array (
Array<Array<Array<CustomObject>>>
) is sorted by the size of the 2D array (Array<Array<CustomObject>>
)
By these three methods, the duplicates should stand one next to the other, but I don't know how to eliminate them without creating too many nested loops to compare the elements.
Example of output for the current implementation:
[[v1], [v2, v3]]
[[v1, v2], [v3]]
[[v1, v2], [v3]]
[[v1, v2], [v2, v3]]
[[v1], [v2, v3]]
[[v1, v2], [v2, v3]]
[[v1], [v2], [v3]]
[[v1], [v2], [v3]]
[[v1], [v2], [v3]]
[[v1], [v2], [v3]]
[[v1], [v2], [v3]]
[[v1], [v2], [v3]]
I already tried using Arrays.equal and deepequal but it gives me an error stating that the method cannot be applied to my array which is of CustomObjects.
The CustomObjects class implements Comparable and I override equals, hashCode and compareTo.
Any suggestions are welcome. Thanks!