Unique values in multidimensional array

431 Views Asked by At

I am looking for a way to remove duplicated values from a multidimensional array

Example

String[][] values = [["A","A"],["A","A"],["B","B"],["B","B"]]

String[][] dupsRemoved = ?

println dupsRemoved 

DESIRED OUTPUT

[["A","A"],["B","B"]]
1

There are 1 best solutions below

1
On BEST ANSWER

You can use

String[][] dupsRemoved = values.toList().unique()

Any reason you're using String arrays? Embrace the lists ;-)

List values = [["A","A"],["A","A"],["B","B"],["B","B"]]

List dupsRemoved = values.unique()

println dupsRemoved