Wednesday 1 July 2015

Java : Collection Framework : Collections (Rotate)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=C1CO1cUjTws&list=UUhwKlOVR041tngjerWxVccw

CollectionsExample.java
import java.util.ArrayList;
import java.util.Collections;

/*
 Method: 

 public static void rotate(List<?> list,int distance)

 Parameters:

 list - the list to be rotated.
 distance - the distance to rotate the list. There are no constraints on this value; 
 it may be zero, negative, or greater than list.size().

 */

public class CollectionsExample
{

    public static void main(String[] args)
    {

        ArrayList<Integer> arrayList = new ArrayList<Integer>();

        arrayList.add(10);
        arrayList.add(20);
        arrayList.add(30);
        arrayList.add(40);
        arrayList.add(50);

        System.out.println("Before rotate , arrayList : " + arrayList + "\n");

        /*
         * Rotates the elements in the specified list by the specified distance.
         */
        Collections.rotate(arrayList, 1);

        System.out.println("After rotate , arrayList : " + arrayList + "\n");

    }

}
Output
Before rotate , arrayList : [10, 20, 30, 40, 50]

After rotate , arrayList : [50, 10, 20, 30, 40]
To Download CollectionsDemoRotateApp Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/CollectionsDemoRotateApp.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment