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

输出结果

循环移动List元素

相关文章:

  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
猜你喜欢
  • 2021-08-01
  • 2021-08-13
  • 2021-11-27
  • 2021-08-10
  • 2021-09-04
  • 2022-03-09
相关资源
相似解决方案