package com.wf.bean;
import java.util.ArrayList;
import java.util.List;
public class Test1 {
/**
* @param args
*/
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
list.add("a");
list.add("b");
list.add("c");
list.add("d");
list.add("e");
System.out.println(list);
System.out.println("---------------------");
swap(list,3,4);
System.out.println(list);
}
@SuppressWarnings("unchecked")
public static void swap(List list,int a,int b) {
String s1= (String) list.get(a);
list.set(a,list.get(b) ) ;
list.set(b, s1);
}
}
|
|