Reverse an ArrayList

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

 * Java Program to reverse ArrayList in place
public class ReverseArrayList 
    public static void main( String[] args )
        List<String> listOfFood  = new ArrayList<String>();
        listOfFood.add("Dark Chocolate");
        listOfFood.add("Pure Vegetables");
        System.out.println("Origibal Array : "+ listOfFood);
        int size = listOfFood.size();
        for(int i=0 ; i< size/2 ; i++){
        	String tmp = listOfFood.get(i);
        	listOfFood.set(i, listOfFood.get(size-i-1));
        	listOfFood.set(size-i-1, tmp);
        System.out.println("Reversed ArrayList : "+ listOfFood);

About sivateja

I am a professional graduate..I am passionate about Latest Technology.
This entry was posted in Programing questions and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s