delete duplicate in an Array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rookTheCook
    New Member
    • Aug 2009
    • 2

    delete duplicate in an Array

    Hi,
    sorry to bother you with that.
    is there any method available in java api to delete duplicates in an array? or do I have to write my own?
    If I have to write my own, what'd be the best approach?

    Thanks,
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by rookTheCook
    Hi,
    sorry to bother you with that.
    is there any method available in java api to delete duplicates in an array? or do I have to write my own?
    If I have to write my own, what'd be the best approach?

    Thanks,
    Arrays can not be shortened so what would you do with the duplicate elements that are supposedly removed from the array? Turn them into null values? Better turn your array into a List and feed that List to a Set (the last one can only contain unique elements). Finally turn that Set into a List again and voila.

    Read the API documentation for the Collection framework and the Arrays utility class.

    kind regards,

    Jos

    Comment

    • rookTheCook
      New Member
      • Aug 2009
      • 2

      #3
      Hi,
      thank JosAH. It really helped,

      rook

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by rookTheCook
        Hi,
        thank JosAH. It really helped,

        rook
        Good; you're welcome of course.

        kind regards,

        Jos

        Comment

        Working...