Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2011
    Posts
    24
    Rep Power
    0

    Default Remove duplicates in 2D array

    Hello,

    Can someone tell me the logic for removing duplicates from 2D array?

    thanks

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    A few questions.
    What happens when a duplicate is removed? Which way to you want to slide the remaining elements? By row or by column?
    For example given this 2x2
    12
    24
    to
    14
    2
    or
    12
    4
    Can you give an example of an array with duplicates and what you want the resultant array to look like?

  3. #3
    Join Date
    Jun 2011
    Posts
    24
    Rep Power
    0

    Default

    I want to use hashset to remove duplicates becoz lines of code is less. I have a 2D array with all the duplicates. Now, I want to remove the duplicates and store the remaining elements into array. Here is the example, and my final array should be 1456,1457,1458,1459 in an array.

    0 1
    0 1458 1457

    1 1457 1459

    2 1456 1458

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    Can you edit your example and show the before and after arrays?

    my final array should be 1456,1457,1458,1459 in an array.
    This looks like a one dim array?

  5. #5
    Join Date
    Jun 2011
    Posts
    24
    Rep Power
    0

    Default

    Here is the example according to array index. My final output should be 1458,1459,1456,1457 in 1D array.

    0 1
    0 1458 1457

    1 1457 1459

    2 1456 1458

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default

    You want to create a one dimensional array from the contents of the two dim array. Is that correct?
    Your output array doesn't have the 0, 1 and 2 in it. Why were these removed?

    Perhaps it'd be less ambiguous if you coded it like an array definition:
    { {123, 1233}, {333, 444}, {234, 444}}

Similar Threads

  1. How can i remove a value from an array?
    By Meta in forum New To Java
    Replies: 3
    Last Post: 01-30-2011, 09:31 PM
  2. Getting rid of duplicates in my Array problem
    By 'Rasta. in forum New To Java
    Replies: 6
    Last Post: 11-20-2010, 05:51 PM
  3. Duplicates in String Array
    By turnergirl24 in forum New To Java
    Replies: 1
    Last Post: 11-04-2009, 11:09 PM
  4. FInd the no. of duplicates in an array
    By singularity in forum Advanced Java
    Replies: 3
    Last Post: 09-04-2009, 09:25 AM
  5. how to remove an object from the array list
    By cecily in forum New To Java
    Replies: 3
    Last Post: 08-02-2007, 02:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •