循环移动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);
	}
}

输出结果

posted on 2019-06-28 22:51  行之间  阅读(839)  评论(0编辑  收藏  举报