嘿伙计们我有用于创建Item对象的类Item
public class Item {
private String id;
private int count;
private String name;
public int 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(int count)
{
this.count=count;
}
public String getItemName()
{
return this.name;
}
public String getItemId()
{
return this.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)
{
this.hold.add(item);
}
ItemList() {
//throw new UnsupportedOperationException("Not yet implemented");
}
public List<Item> getItemSet()
{
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;
}
}
首先,我将I1,I2,I3项目添加到Itemlist,如下所示
{I1}
{I2}
{I3}
现在我想创建一个Item对象的子集,如下所示,并添加到ItemList,其中每个子集将包含2个项目
{I1 I2}
{I1 I3}
{I2 I3}
请帮助创建子集 后来我甚至想要有2个或更多项的子集 我想编写一个函数来帮助我创建n个项的子集 请帮忙