Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is the best method to sort strings in real time or off line ?

 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all
i have program that needs to collect strings from different kinds of resources.
now the strings can be duplicated and i need to sort them i wander what will be the best way
to do that or to divide the job to 2 phases in which first phase will collect the data without checking duplication
just write then to file and in the second phase i will use unix "sort -u" on the files and then the program will handle the
new information
or
do it all in one phase and every string will be kept into map and then every time the program collects new string it will check agents the map
to see if it already there .
in term of speed what will be the best solution ?
Thanks
 
Campbell Ritchie
Sheriff
Posts: 48406
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Putting them into a Map or Set would work; there are Set implementations which sort automatically.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic