首页 > 代码库 > 动态数组ArrayList的使用
动态数组ArrayList的使用
1.定义类
package com.realhope.rmeal.bean;
/**
*
* @author Wucy
* 菜谱类
*/
public class Menu{
private Integer _id;
private Integer typeID; // 菜单类型
private String name; // 名称
private String description; // 菜谱介绍
private Integer price; // 价格
private String unit; // 单位
private String pic; // 图片路径
private String remark; // 备注
public Menu() {
super();
}
public Menu(Integer _id, Integer typeID, String name, String description,
Integer price, String unit, String pic, String remark) {
super();
this._id = _id;
this.typeID = typeID;
this.name = name;
this.description = description;
this.price = price;
this.unit = unit;
this.pic = pic;
this.remark = remark;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public Integer get_id() {
return _id;
}
public void set_id(Integer _id) {
this._id = _id;
}
public Integer getTypeID() {
return typeID;
}
public void setTypeID(Integer typeID) {
this.typeID = typeID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
public String getPic() {
return pic;
}
public void setPic(String pic) {
this.pic = pic;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}
2.引入包
import java.util.ArrayList;
3.定义数组
private List<Menu> lstDate = new ArrayList<Menu>();
4.使用实例:
lstDate.clear();//清空数组
lstDate = new MenuManager(this).queryMenus(type_id);//实例
PageCount = (int) Math.ceil(lstDate.size() / PAGE_SIZE);// 数组大小
动态数组ArrayList的使用