wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Vector" Watch "Vector" New topic
Author

Vector

mitesh mehta
Greenhorn

Joined: Aug 29, 2002
Posts: 25
Hi all....
I am adding elements to a Vector and i want the elements to be added in a ascending format.Can anyone suggest how to get the same?
Any help will be appreciated.
Thanks in advance.
Mitesh
Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
Try using some class that implements SortedSet interface such as TreeSet.
Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
Example:
Set s=new TreeSet();
s.add("leandro");
s.add("jose");
s.add("pedro");
s.add("carlos");
s.add("alex");
Iterator i=s.iterator();
while(i.hasNext()){
System.out.println(i.next());
}
this will print all the elements in the natural order, I added string elements, String class implements java.lang.Comparable, if your object does not implements Comparable, you can create a Comparator, just implementing java.util.Comparator. Hope it helps!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Vector
 
Similar Threads
Passing Vector elements to an array
I want to iterate all elements in vector and store it in another vector..?
Vectors
order of elements in Vector
Vector <Object>