(List)写一个函数reverseList,该函数能够接受一个List,然后把该List 倒序排列。 例如: List list = new ArrayList(); list.add(“Hello”); list.add(“World”); list.add(“Learn”); //此时list 为Hello World Learn rever
import java.util.ArrayList; import java.util.List; public class AA { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("Hello"); list.add("World"); list.add("Learn"); System.out.println("倒序之前:"+list); AA dx = new AA(); dx.reverseList(list); } public void reverseList(List<String> list) { List<String> list1 = new ArrayList<>(); for(int i =list.size()-1;i>=0;i--) { list1.add(list.get(i)); } list= list1; System.out.println("倒序之后: "+list); } }