Does anyway know of a method which will do this on a vector, or a container which automatically sorts them? Otherwise i might try and use the ascii values. But just wondering what you peeps thought?

Recommended Answers

All 4 Replies

Check the collections API, there are some sorted implementations you can use.
No sorted List is provided but it isn't that hard to make one if you use another collection to back it which is sorted itself (or use that one directly if you have no need of the List interface per se).

And before I forget: don't use Vector. It's an old relic and has long since been replaced by the far more efficient ArrayList.

If you use an ArraList like jwenting suggested, you can use:

Collections.sort(ArrayList);

You might could use that on a vector, but I doubt it. Never tried.

Also, isn't there some way to use the comparator interface to sort?

I actually used a SortedSet which seems to have done the job nicely. Thanks for the tip on Vectors, i see they have synchronisation overhead - what other problems have you found with them. I couldn't find a clear explanation. Thanks again guys :)

The performance penalty alone is enough reason.
The rest is historical. Until recently Vector was not part of the Collections framework. It still is an oddball with regard to implementing methods of the framework.
Personally I don't understand why Sun didn't just deprecate the class seeing as a perfectly functional alternative is available.

ArrayList is a far cleaner as well as better performant solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.