- public static void main(String[] args) {
- ArrayList<String> list = new ArrayList<>();
- list.add("a");
- list.add("b");
- list.add("d");
- list.add("c");
- for (int start = 0, end = list.size() - 1; start <= end; start++, end--) {
- Object temp = list.get(start);
- list.set(start, list.get(end));
- list.set(end, (String) temp);
- }
- System.out.println(list);
- }
复制代码
|
|