Latest web development tutorials

Java Examples - List circulating movement elements

Java Examples Java Examples

The following example demonstrates how to use the Collections class rotate () loop to move elements by the second parameter specifies the starting position of:

/*
 author by w3cschool.cc
 Main.java
 */

import java.util.*;

public class Main {
   public static void main(String[] args) {
      List list = Arrays.asList("one Two three Four five six".split(" "));
      System.out.println("List :"+list);
      Collections.rotate(list, 3);
      System.out.println("rotate: " + list);
   }
}

The above code is run output is:

List :[one, Two, three, Four, five, six]
rotate: [Four, five, six, one, Two, three]

Java Examples Java Examples