Have all your classes of items implement the same interface, "Item". Then make the arraylist of type Item.
Or, if the items have common data (such as price) you could have them all extend the same class.
Example of extending the same abstract class:
public abstract class Item {
private int value;
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
public class Weapon extends Item {
private int damage;
public Weapon(int value, int damage) {
this.setValue(value);
this.damage = damage;
}
}
ArrayList declaration:
List<Item> inventory = new ArrayList<Item>();
inventory.add(new Weapon(10, 25));
Item, perhaps) that defines methods inherent to any item. Because each type of item would extendItem, you could then useList<Item>, orItem[]to store all of your items.Object[]if you need to. My recommendation is to make 1 item class, calledItem. Then you can have other classes extend it. Then make anItem[].