日期:2014-05-20 浏览次数:20553 次
import java.util.ArrayList;
public class AlterList{
//初始化ArrayList
public ArrayList list(){
//初始化ArrayList
ArrayList<Integer> list=new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
return list;
}
//修改ArrayList
public void alter(ArrayList list){
//修改list中的数据
list.set(0,8);
list.set(1,6);
list.set(2,5);
}
//主函数
public static void main(String[] args){
AlterList al = new AlterList();
//初始化ArrayList
ArrayList<Integer> list = al.list();
al.alter(list);
//输出结果为8,6,5
for(Integer lists:list){
System.out.println(lists);
}
}
}