title: Setting up a toString() method for an array list
body: <p>Sorry for what is probley a simple question but how would i go about setting up a toString() method for an array list? </p>
  
  <p>is it as simple as </p>
  
  <pre><code>points = new ArrayList&lt;Point&gt;();
  public String toString() {
  return points.toString();}
  </code></pre>
  
  <p>which does not seem to be working for me, or would it be more complex since it is a array list? Because for some reason when i execute mine like this its only printing the first value or object. </p>
  
  <p>P.S I'm trying to return all the values that i have already added to my list. </p>
  
  <p>More in detail
  constructer</p>
  
  <pre><code>public Cloud() {
      points = new ArrayList&lt;Point&gt;();
  }
  </code></pre>
  
  <p>add point</p>
  
  <pre><code>public void addPoint(Point p) { // done
      if (points.contains(p)) {
          // if p is already in the list it does nothing
      } else {
          points.add(p); // if p was not in the list it adds it to the end
      }
  }
  </code></pre>
  
  <p>toString </p>
  
  <pre><code>public String toString() {
      return points.toString();
  }
  </code></pre>
  
  <p>main</p>
  
  <pre><code>public static void main(String[] args) {
      Cloud cloud = new Cloud();
  
      cloud.setDebug(false);
      System.out.println("cloud.debug OFF");
  
      System.out.println("initial cloud: " + cloud.toString());
      Point p1 = new Point(3.0, 1.0);
      cloud.addPoint(p1);
  
      Point p2 = new Point(2.0, 2.0);
      cloud.addPoint(p2);
  
      Point p3 = new Point(1.5, 1.5);
      cloud.addPoint(p3);
  
      Point p4 = new Point(3.0, 0.0);
      cloud.addPoint(p4);
  
      System.out.println("final cloud: " + cloud);
  </code></pre>
  
  <p>This is just printing final cloud: (3.0,1.0)     while it should be printing final cloud: [(3.0,1.0), (2.0,2.0), (1.5,1.5), (3.0,0.0)]</p>
  
  <p>edit: Points class</p>
  
  <pre><code>public class Point {
  
  private double x;
  private double y;
  
  public static final double EPSILON = 1e-5;
  public static boolean debug = false;
  
  public Point(double x, double y) {
      this.x = x;
      this.y = y; // Done sets the x,y private types to the x,y type provided
                  // in the ()
  }
  
  public Point() {
      this(0.0, 0.0); // calls the point (double x,double) constructer with
                      // the given arguments
  } // inturn setting x and y == 0.0
  
  public double getX() {
      return x; // returns the private value of x when called in the main
                  // method
  } // so it can't be changed by the user
  
  public double getY() {
      return y; // return the private value of y when called in the main
                  // method so it can't be changed
  } // by the user
  
  public String toString() {
      return "(" + x + "," + y + ")"; // done by teacher sets the toString
                                      // method and implemetns it
  }
  
  public boolean equals(Point p) {
      if (Math.abs(this.getX()) - Math.abs(p.x) &lt; EPSILON) {
          return true; // checks if x - p.x is less than epsilon which covers
                          // the round off
      }
      if (Math.abs(this.getY()) - Math.abs(p.y) &lt; EPSILON) {
          return true; // checks if y-p.y is less than epsilon which covers
                          // the round off
      }
      return false; // both these methods test for equality using epsilon,
                      // becuae we are dealing with
  } // doubles, so roundof can occur
  
  public boolean equals(Object obj) { // this was given to us
      if (obj instanceof Point) {
          Point p = (Point) obj; // This method overrides the object equals
                                  // method and the calls
          return equals(p); // the clas's equals(point) method
      }
      return false;
  }
  
  // TODO Implement Point.euclidDist
  /**
   * 
   * @param p
   * @return Euclidean distance of this point to point p
   */
  public double euclidDist(Point p) {
      double distance = 0;
      double firstvalue;
      double secondvalue;
      distance = Math.sqrt(((this.getX() - p.x) * (this.getX() - p.x)) // calculate
                                                                          // the
                                                                          // distance
              + ((this.getY() - p.y) * (this.getY() - p.y))); // between the
                                                              // two points
      // firstvalue= Math.pow(this.getX()-p.x, 2);
      // secondvalue= Math.pow(this.getY()-p.y, 2);
      // distance = Math.sqrt(firstvalue + secondvalue);
  
      return distance;
  }
  
  /**
   * @param args
   *            : no args
   */
  public static void main(String[] args) {
  
      // test all methods
  
      if (debug)
          System.out.println("debug ON");
      else
          System.out.println("debug OFF");
  
      System.out.println("EPSILON: " + Point.EPSILON);
  
      Point origin = new Point();
      Point p1 = new Point(0.0, 4.0);
      Point p2 = new Point(3.0000001, 3.9999999);
      Point p3 = new Point(3.0, 4.0);
  
      Point p4 = new Point(0.0, 5.0);
      Point p5 = new Point(12.0, 0.0);
  
      System.out.println("origin: " + origin);
      System.out.println("p1: " + p1);
      System.out.println("p2: " + p2);
      System.out.println("p3: " + p3);
      System.out.println("p4: " + p4);
      System.out.println("p5: " + p5);
  
      if (p2.equals(p3))
          System.out.println(p2 + " equals " + p3);
      else
          System.out.println(p2 + " does not equal " + p3);
  
      System.out.println("Euclidean distance between " + origin + " and "
              + p1 + ": " + origin.euclidDist(p1));
  
      System.out.println("Euclidean distance between " + p1 + " and " + p3
              + ": " + p1.euclidDist(p3));
  
      System.out.println("Euclidean distance between " + p3 + " and "
              + origin + ": " + p3.euclidDist(origin));
  
      System.out.println("Euclidean distance between " + p4 + " and " + p5
              + ": " + p4.euclidDist(p5));
  
  }
  </code></pre>
  
  <p>}</p>