Set class (order)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mokita
    New Member
    • Mar 2007
    • 11

    #1

    Set class (order)

    Hello,

    I am using Set class to remove duplicates from an array. The order in the array is important for my work. After removing the duplicates i create another array containing the elements of the Set, but I realize that the order is really different from the first array. Does anyone know how can I have the order of the Set it was inserted first?

    The code I am using:
    // my is the array containing the information, which can can contain duplicates.
    Set mySet = new HashSet(Arrays. asList(my));
    // creating new array with the elements of mySet
    String [] result = (String[])(mySet.toArray (new String[mySet.size()]));

    Thank you in advance,

    Mokita
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Have a look at the LinkedHashSet class.

    kind regards,

    Jos

    Comment

    • Mokita
      New Member
      • Mar 2007
      • 11

      #3
      Originally posted by JosAH
      Have a look at the LinkedHashSet class.

      kind regards,

      Jos


      Thank you very much for the hint.

      Mokita

      Comment

      Working...