wood burning stoves*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sorting elements Comparator or Collection
 
Similar Threads
Casting and Interfaces
Looks like nobody failed?
JInsight
Sorting the best way
Sorting elements of Vectors in multiple ways