Home > Java > javaTutorial > Java Example - Array Reverse

Java Example - Array Reverse

黄舟
Release: 2017-02-18 10:04:15
Original
1398 people have browsed it

In the following example, 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);
   }
}
Copy after login

The output result of running the above code is:

反转前排序: [A, B, C, D, E] 
反转后排序: [E, D, C, B, A]
Copy after login

The above is the Java example - array Reversed content, please pay attention to the PHP Chinese website (www.php.cn) for more related content!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template