|
Java 实例 - List 循环移动元素
以下实例演示了如何使用 Collections 类的 rotate() 来循环移动元素,方法第二个参数指定了移动的起始位置: 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 ) ;
}
} |
以上代码运行输出结果为:
List :[one, Two, three, Four, five, six]
rotate: [Four, five, six, one, Two, three]
程序猿的技术大观园:www.javathinker.net
[这个贴子最后由 flybird 在 2020-01-22 21:47:08 重新编辑]
|
|