title: How to get values from an ArrayList from another class once it has been defined?
body: <p>I cant get my head around accessing information that I have written to an <code>ArrayList</code> in another code works. 
  I have been trying to figure it out from other answers that people have gotten but I never seem to get it right.</p>
  
  <p>I always seem to get the same response <code>java.lang.IndexOutOfBoundsException</code>: Index: 0, Size: 0 . It doesn't work and I'm pretty damn sure that it is something simple and that just makes it all the more infuriating.</p>
  
  <p>So in my testing project I have a getter and setter class</p>
  
  <pre><code>import java.util.ArrayList;    
  class Values {    
      ArrayList&lt;Double&gt; values = new ArrayList&lt;&gt;();
  
      public ArrayList&lt;Double&gt; getValueList() {
          return values;
      }
  
      public void addValue(double price) {
          values.add(price);
      }
  
      public double getValue(int location) {
          return values.get(location);
      }    
  }
  </code></pre>
  
  <p>Then I have another class that uses these methods to write to the <code>ArrayList</code>.</p>
  
  <pre><code>import java.util.ArrayList;
  
  public class ValuesTesting {
      Values v = new Values();
      public static void main(String[] args) {
          ValuesTesting vT = new ValuesTesting();
          vT.addValue1();
          vT.addValue2();
          ValueTesting2 vT2 = new ValueTesting2();
          vT2.main();
      }
  
      private void addValue1() {
          double price = 1502.0;
          v.addValue(price);
      }
  
      private void addValue2() {
          double price = 1204.0;
          v.addValue(price);
      }
  }
  </code></pre>
  
  <p>And then I want to read the values from my third class which has this code:</p>
  
  <pre><code>import java.util.ArrayList;
  public class ValueTesting2 {
      Values v = new Values();
      public void main() {
          getList();
      }
      private void getList() {
          System.out.println(Double.toString(v.getValueList().get(0)));
      }
  }
  </code></pre>
  
  <p>I know the naming is completely wrong but I only intended this to be a class that I could finally figure this out on, but I just cant. </p>
  
  <p>Any help would be great, thanks :)</p>