List circulation moving element

List circulation moving element

Use rotate Collections class () to move the loop elements, the method of the second argument specifies the start position:

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

Output

Guess you like

Origin www.cnblogs.com/zxfei/p/11105157.html
Recommended