• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

removing duplicate values from list

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to remove duplicate values from list
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

abhinas raj wrote:how to remove duplicate values from list


abhinas, this site is NotACodeMill (←click).

What have you tried? How do you think you might do it?

ShowSomeEffort (←click) and you're much more likely to get help.

But just as a starter for you, have a look at List.indexOf(Object).

Winston
 
abhinas raj
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i was doing it like first store it in set (since set does not allow duplicate value to be stored), but if i do like that the order of the elements will be changed. so we cant
second method i was trying that match each element with all the previous elements if equal then delete this .. but that also does not look optimized. i want some optimized solution that's why i posted only question
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

abhinas raj wrote:i was doing it like first store it in set (since set does not allow duplicate value to be stored), but if i do like that the order of the elements will be changed. so we cant


That's not necessaily true. A LinkedHashSet does preserve addition order.

second method i was trying that match each element with all the previous elements if equal then delete this .. but that also does not look optimized. i want some optimized solution that's why i posted only question


If this is another interview question, did they ask you to produce an optimized solution? If not, don't worry about it.

Winston
 
abhinas raj
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks all for your valuable comments
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

abhinas raj wrote:thanks all for your valuable comments


You're welcome.

And BTW, your thinking - ie, to put them in a Set - was spot on; and very "Object-oriented".

Winston
 
reply
    Bookmark Topic Watch Topic
  • New Topic