循环移动List元素

List 循环移动元素

使用 Collections 类的 rotate() 来循环移动元素,方法第二个参数指定了移动的起始位置:

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);
    }
}

输出结果

猜你喜欢

转载自www.cnblogs.com/zxfei/p/11105157.html