Java Example - Array Reverse
In the following examples we use Collections.reverse(ArrayList) to reverse the array:
/* author by w3cschool.cc 文件名:Main.java */ import java.util.ArrayList; import java.util.Collections; public class Main { public static void main(String[] args) { ArrayList arrayList = new ArrayList(); arrayList.add("A"); arrayList.add("B"); arrayList.add("C"); arrayList.add("D"); arrayList.add("E"); System.out.println("反转前排序: " + arrayList); Collections.reverse(arrayList); System.out.println("反转后排序: " + arrayList); } }
The output result of running the above code is:
反转前排序: [A, B, C, D, E] 反转后排序: [E, D, C, B, A]