File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Sorting elements Comparator or Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Sorting elements Comparator or Collection" Watch "Sorting elements Comparator or Collection" New topic
Author

Sorting elements Comparator or Collection

Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
Can someone show me how to sort an array or Vector using
these classes?
Thanks
Dale

------------------
By failing to prepare, you are preparing to fail.
Benjamin Franklin (1706 - 1790)


By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Kaspar Dahlqvist
Ranch Hand

Joined: Jun 18, 2001
Posts: 128
Howdy!
Here goes:
import java.util.*;
class T {
public static void main (String[] a) {

Vector v = new Vector();
v.add("Nisse");
v.add("Runar");
v.add("Adam");
v.add("Einar");
v.add("Kalle");
v.add("Runnar");
Collections.sort(v);
for (int i = 0; i < v.size(); i++)
System.out.println(v.elementAt(i));
}
}
Hope this helps!
//Kaspar
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Sorting elements Comparator or Collection