没做出来
第四题 (List)写一个函数reverseList,该函数能够接受一个List,然后把该List 倒序排列。 例如:
List list = new ArrayList();
list.add(“Hello”);
list.add(“World”);
list.add(“Learn”); //此时list 为Hello World Learn
reverseList(list); //调用reverseList 方法之后,list 为Learn World Hello
package Test03; import java.util.ArrayList;
import java.util.List; public class ReverseList { public static void main(String[] args) { List<String> list = new ArrayList<>();
list.add("Hello");
list.add("World");
list.add("Learn"); //此时list 为Hello World Learn StringBuffer a = new StringBuffer();
for(String s:list){
a.append(s);
}
System.out.println(a.toString());
//reverseList(list); //StringBuilder b = new StringBuilder(list.toString()); //System.out.println(list);
System.out.println(a.reverse().toString()); } }