Removing Duplicates and Originals From ArrayList

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AllBeagle
    New Member
    • Sep 2008
    • 13

    Removing Duplicates and Originals From ArrayList

    Here is what might seem to be an odd request. Does anyone know how I can find a duplicate in an arraylist and delete both the duplicate and the original, leaving me with only the items that didn't have any duplicates? This might be bass-ackwards, but I'm trying to get something to work really quick that I don't have time right now to research. I am able to sort but I keep getting index errors, which I assume are happening when I get to the end of the arraylist.

    If I remove a record at "i", does it shift all the records up so technically I would have to remove at "i" again to delete both. I've tried this and it still throws back an exception, but I'm trying to get some more insight as far as how an arraylist works.

    Thanks!
  • cloud255
    Recognized Expert Contributor
    • Jun 2008
    • 427

    #2
    An array list removes an item from the list and then moves all the other items up in the list so that there are no 'empty' elements:

    lets say we have an arralist containing 'zero', 'one', 'two'. when then remove element 1 i.e. 'one'.

    the list now has 2 elements namely 'zero' and 'two'.

    If you still have problems with the indexes being out of bounds, post your code so that we may investigate what is causing the problem.

    Comment

    Working...