简体   繁体   中英

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},};

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM