user3270422
user3270422

Reputation: 19

Removing duplicates from array without using any collection api of java

Can you please advise I have the below array for which I want to remove duplicates but without using any collection api , please advise how to achieve this...

  int[][] test = new int[][]{
            {1, 1, 2, 2, 3, 4, 5},
            {1, 1, 1, 1, 1, 1, 1},
            {1, 2, 3, 4, 5, 6, 7},
            {1, 2, 1, 1, 1, 1, 1},};

Upvotes: 0

Views: 811

Answers (1)

AlexR
AlexR

Reputation: 115368

Since you are dealing with int array and values are relatively small I'd suggest you to create temporary boolean array where the numbers from the source array are used as indexes. Then you just have to iterate over the source array, put true to appropriate cell of your temporary array. At the next iteration go over the temporary array and indexes of elements that are true.

Upvotes: 2

Related Questions