So much information in a short declaration. An experienced programmer looks at TreeSet countyNames and instantly knows: this is a sorted collection of Strings without duplicates, and I can be sure that this is true at every moment.If you need duplicates, stick to your List. Depending on your situation this may be a pro or a con. Never worry about is this list really sorted right now becaude a TreeSet is always sorted, no matter what you do.This has some subtle, but important advantages: This kind of collection sorts your entries just when they are inserted. If you are free to decide, and if your application might get more complex, then you might change your code to use a TreeSet instead. If you combine it with the advice from Tom Hawtin - tackline, you get: (listOfCountryNames, Collator.getInstance()) Then Thilos answer will be the best way to do it. If you are forced to use that List, or if your program has a structure like
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |