1ãArrayListæ¯å¨ææ°ç»ï¼Listæ¯ä¸ä¸ªæ¥å£ï¼ä¸è½å®ä¾åï¼éè¦å®ä¾åä¸ä¸ªArrayListï¼
List list = new ArrayList();
2ã使ç¨list .add(ä»»ä½å¯¹è±¡);å°±å¯ä»¥è¿è¡æ·»å äºã代ç å¦ä¸ï¼
beanç±»
package com.whn.bean;
public class ListBean {
private String name;
private String pwd;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public String getPwd() {
return pwd;
}
}
æµè¯ç±»package com.whn.test;
import com.whn.bean.ListBean;
import java.util.ArrayList;
import java.util.List;
public class ListTest {
//æµè¯
public static void main(String[] args) {
List<ListBean> list = new ArrayList<ListBean>();//å®ä¾åä¸ä¸ªarrayList
//æ·»å
for(int i=10;i<20;i++){
ListBean listBean = new ListBean();
listBean.setName("name"+i);
listBean.setPwd("pwd"+i);
list.add(listBean);//ælistBeanæ·»å å°arrayListä¸
}
//ææ°æ®ååºæ¥
for(ListBean lb:list){
System.out.println(lb.getName());
System.out.println(lb.getPwd());
}
}
}
温馨提示:答案为网友推荐,仅供参考