File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sorting elements Comparator or Collection

 
Dale DeMott
Ranch Hand
Posts: 515
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Kaspar Dahlqvist
Ranch Hand
Posts: 128
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic