title: How to write a toString method for ArrayList?
body: <p>I am having a hard time finding out how to write my toString Method to get the output of each of my bears in my program. I want the output to show "Race - Points - TotalPoints". But can't manage to get it right even though the rest of the code seems to compile.</p>
  
  <p>Do i need to have the toString defined in both classes or what am I missing? I have checked a couple of other questions that are resembling and that seems to be an alternativ? But how is it most effectively implemented? </p>
  
  <p>First off the bear class: </p>
  
  <pre><code>import java.util.ArrayList;
  
  public class Bear {
  
      public static void main(String[] args) {
  
          Bear b = new Bear("Sebastian", 100, "Brownbear");
          ArrayList &lt;Bear&gt; bears = new ArrayList&lt;Bear&gt;();
          bears.add(b);
  
      }
  
      private String name;
      private int points;
      private String race;
  
  
      public Bear(String name, int points, String race) {
          this.name = name;
          this.points = points;
          this.race = race;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getRace() {
          return race;
      }
  
      public void setRace(String race) {
          this.race = race;
      }
  
      public int getInitialPoints() {
          return points;
      }
  
      public int getPoints() {
          int oldPoints = points;
          points /= 2;
          return oldPoints;
      }
  }
  </code></pre>
  
  <p>Secondly the BearCollection class:</p>
  
  <pre><code>import java.util.ArrayList;
  
  public class BearCollection {
  
      ArrayList &lt;Bear&gt; bears = new ArrayList&lt;Bear&gt;();
  
       int totalPoints = 0;
  
      public void add (Bear b) {
  
          for (Bear inCollection : bears) {
              if(b.getName().equals(inCollection.getName())) {
                  return;
              }
          }
  
          for (Bear inCollection : bears)
          if (b.getRace().equals(inCollection.getRace())) {
  
              for(int i =  bears.size(); i &gt; 0; i --) {
                  if(bears.get(i).getRace().equals(b.getRace())) {
                      b.getPoints(); 
                      i = 0;
                  } 
              }
          }
  
          totalPoints += b.getInitialPoints();
  
  
          bears.add(b) ;
      }
  
  public String toString(){
  
      return ;
  }
  </code></pre>