Wednesday, March 11, 2015

Swap elements of Java Array in java pgm



Swap elements of Java ArrayList

import java.util.ArrayList;
import java.util.Collections;
public class SwapElementsOfArrayListExample
{
 public static void main(String[] args)
{
ArrayList arrayList = new ArrayList();
arrayList.add("A");
arrayList.add("B");
arrayList.add("C");
arrayList.add("D");
arrayList.add("E");
System.out.println("Before swaping, ArrayList contains : " arrayList);
Collections.swap(arrayList,0,4);
System.out.println("After swaping, ArrayList contains : " + arrayList);
   }
}

1 comment:

  1. Good example for swaping element in arraylist .There is one more good way to swap element in arraylist visit
    swap element in ararylist

    ReplyDelete