Monday, 18 May 2015

How to reverse the ArrayList elements without using reverse method in JAVA

public class ArrayList1{
public static void main(String[] args){
ArrayList al= new ArrayList();
al.add(10);
al.add(20);
al.add(30);
System.out.println(al);      //[10 20 30]
int length=al.size();
for(int i=length-1; i>=0;i--){
System.out.println(al.get(i));   //30 20 10
}
}
}

No comments:

Post a Comment