java.util.Collections.reverse() 方法
描述
reverse(List<?>) 方法用于反转指定列表中元素的顺序。
声明
以下是 java.util.Collections.reverse() 方法的声明。
public static void reverse(List<?> list)
参数
list − 这是要反转其元素的列表。
返回值
NA
异常
UnsupportedOperationException − 这是如果指定的列表或其列表迭代器不支持集合操作。
示例
下面的例子展示了 java.util.Collections.reverse() 的用法。
package com.tutorialspoint;
import java.util.*;
public class CollectionsDemo {
public static void main(String[] args) {
// create array list object
ArrayList<String> arrlst = new ArrayList<String>();
// populate the list
arrlst.add("A");
arrlst.add("B");
arrlst.add("C");
arrlst.add("D");
arrlst.add("E");
System.out.println("The initial list is :"+arrlst);
// reverse the list
Collections.reverse(arrlst);
System.out.println("The Reverse List is :"+arrlst);
}
}
让我们编译并运行上面的程序,这将产生以下结果.
The initial list is :[A, B, C, D, E] The Reverse List is :[E, D, C, B, A]

