How do you sort the elements of a vector?

John Zukowski

Since the Vector class implements the List interface, you can call the Collections.sort() method to sort the elements in place. You can also manually insert elements into a Vector to keep the vector sorted. Of course, if keeping sorted access is such a big deal, you should consider using a different, more appropriate data structure like a TreeSet.

For 1.1 Java users, you'll need to sort the elements yourself. There is no built-in support for this. A better option might be to sort the elements as you insert each element.

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact