title: How to create a println/print method for a custom class
body: <p>I'm working in Java on a project that requires me to make a few 'container' classes, if you will. Here is a simple version of one:</p>
  
  <pre><code>public class Pair{
  
      Object KEY;
      Object VALUE;
  
      public Pair(Object k, Object v)
      {
          KEY = k;
          VALUE = v;
      }
  
      public Object getKey()
      { return KEY; }
      public Object getValue()
      { return VALUE; }
  }
  </code></pre>
  
  <p>(Please note, this is severely simplified and I am using proper set/get methods in the final version.)</p>
  
  <p>My question is this:</p>
  
  <p>When calling the println method with an ArrayList as the parameter, for example:</p>
  
  <pre><code>ArrayList&lt;String&gt; arr = new ArrayList&lt;String&gt;();
  arr.add("one");
  arr.add("two");
  System.out.println(arr);
  </code></pre>
  
  <p>Java automatically knows how to print each 'node' or element of the ArrayList correctly. </p>
  
  <p><strong>Is there a way to write a method to allow the println method to correctly print my Pair class?</strong></p>