Friday, March 6, 2009

collections class reverse string



package myutil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CollectionsReverse {
public static void main(String [] args ) {
List l=new ArrayList();
l.add("Z");
l.add("A");
l.add("H");
l.add("E");
l.add("O");
l.add("B");
l.add("F");
l.add("Y");
System.out.println("The List"+l);
Collections.reverse(l);
System.out.println("The Reversed List"+l);
}
}

output:
The List[Z, A, H, E, O, B, F, Y]
The Reversed List[Y, F, B, O, E, H, A, Z]



0 comments:

Post a Comment