title: Java - Printing an ArrayList of Objects using multiple Classes
body: <p>I am constructing a rather large program that holds a lot of hard-coded data from a game (DnD 4e). For the sake of organization, I have broken this up into different classes (separate .java files) to avoid a 10k+ line innavigable program. I am storing an <code>ArrayList</code> of objects called <code>Item</code>. Each <code>Item</code> contains a <code>String name</code>, <code>String price</code>, and <code>String description</code>.</p>
  
  <p>The problem is that I have all of the items stored in one method, <code>Item</code>, and the <code>ArrayList&lt;Item&gt;</code> in another method, <code>InvList</code>. How can I print every <code>Item</code> in the <code>ArrayList&lt;Item&gt;</code>? I am more experienced in Arrays, and I realize I could use a for loop and just iterate through the Array, but I'm unaware of the method of doing so for ArrayLists.</p>
  
  <p>Main Method:</p>
  
  <pre><code>public class DnD {
      . . .
      public static void main(String[] args) {
          . . .
          System.out.println("The inventory has "+inv.size()+" items.");
          inv.add(Item.Candle);
          printInv(inv);
      } //main()
  } //DnD
  </code></pre>
  
  <p>InvList Method, to keep track of people's inventories and the methods to manage them:</p>
  
  <pre><code>public class InvList {
      public static ArrayList&lt;Item&gt; inv = new ArrayList&lt;&gt;();
      // I want to create multiples ArrayLists for multiple people, ...
      // ... so there will be several here.
  } //InvList()
  </code></pre>
  
  <p>Item Method, housing all of the Item information and management methods:</p>
  
  <pre><code>public class Item {
      . . .
      public String name;
      public String price;
      public String description;
      public static Item Candle = new Item("Candle", 1, "Provides dim light for 2 squares, and lasts for 1 hour.");
      public Item(String _name, double _price, String _desc) {
          name = _name;
          price = priceConverter(_price); //separate method, 
          description = _desc;
      } //Item()
      . . .
  } //Item
  </code></pre>
  
  <p>Any attempt I make just ends up print hashcodes or giving errors. I've looked through many posts here that talk about overwriting <code>toString()</code> and what not, but I have not found an example of how to do so from other classes; these examples all seem to demonstrate how to do it if everything is in the <em>exact</em> same class/file. Am I doomed to just making one large mega file for everything? Or can I use three different classes here to print this one <code>ArrayList&lt;Item&gt;</code>?</p>
  
  <p>Side note: let me know if I'm overkilling the <code>code</code> words, I'm trying to get a sense of what's acceptable over-formatting here.</p>