title: Unable to print arraylist of different data types using java
body: <p>I have a class:</p>
  
  <p><strong>sample.java</strong></p>
  
  <pre><code>class sample
  
  int val;
  String str;
  </code></pre>
  
  <p><strong>constructor</strong></p>
  
  <pre><code>sample(String str,int val)
  
  str=this.str;
  
  val=this.val
  </code></pre>
  
  <p><strong>test.java</strong></p>
  
  <pre><code>ArrayList&lt;sample&gt; lst=new ArrayList&lt;sample&gt;();
  
  lst.add(new sample("somedata",33)):
  
  lst.add(new sample("somedata",33)):
  </code></pre>
  
  <p>send(lst) sending arraylist obj over a network.but i was wondering how i can print the values in the arraylist. I tried using iterator but it is only showing object references.</p>