我有一个Item
类,其中id
, count
,name
作为实例变量。我想根据计数对项目进行排序。请告诉我如何去做。我可以在我的项目类中定义任何方法来对项目进行排序?
下面是我的项目类
public class Item {
private String id;
private String count;
private String name;
Item() {
}
public String getcount() {
return this.count;
}
public Item(String name) {
this.name = name;
this.id = "";
}
public Item(String id, String name) {
this.name = name;
this.id = id;
}
public Item(String id, String name,String count) {
this.name = name;
this.id = id;
this.count=count;
}
public String getItemName() {
return this.name;
}
public String getItemId() {
return this.id;
}
public void createItem(String id, String name) {
this.name = name;
this.id = id;
}
public Item returnItems(ItemList itemset) {
Item item = null;
return item;
}
}
我也有一ItemList
堂课,里面有物品。
public class ItemList implements Iterable<Item> {
private List<Item> hold = new ArrayList<Item>();
ItemList(Item item) {
// hold = new ArrayList<Item>();
this.hold.add(item);
}
ItemList() {
//throw new UnsupportedOperationException("Not yet implemented");
}
public List<Item> getItemList() {
return this.hold;
}
public void addItems(Item item) {
//hold = new ArrayList<Item>();
this.hold.add(item);
}
@Override
public Iterator<Item> iterator() {
Iterator<Item> item = hold.iterator();
return item;
}
}