title: Obtain values from array in one class from another class
body: <p>I have this code in a class and want to ideally copy the values in the <code>adjclose</code> array list to another class for further process while preserving the original data.  <p>I am able to see that the arraylist is populated with the values with the <code>println</code> statement prior to the <code>return</code> statement as the array is being populated.  <p>The <code>main</code> method then iterates through the arraylist to again show the values for each element in the arraylist <code>adjclose</code>.  </p>
  
  <p>How can I get to the <code>adjclose</code> arraylist from another class to enable me to copy them to a new arraylist to process further?</p>
  
  <pre><code>public ArrayList&lt;Double&gt; getadjClose(String symbol) {
      String baseUrl = "http://ichart.finance.yahoo.com/table.csv?ignore=.csv";
      baseUrl += "&amp;s=" + symbol;
      baseUrl += "&amp;a=" + startMonth;
      baseUrl += "&amp;b=" + startDay;
      baseUrl += "&amp;c=" + startYear;
      baseUrl += "&amp;d=" + endMonth;
      baseUrl += "&amp;e=" + endDay;
      baseUrl += "&amp;f=" + endYear;
      baseUrl += "&amp;g=" + freq;
      URL url;
      ArrayList&lt;Double&gt; adjclose = new ArrayList&lt;Double&gt;();
      System.out.print("Opening URL: ");
      System.out.print(baseUrl);
      System.out.println(" ");
      int counter = 0;
      try {
          url = new URL(baseUrl);
          BufferedReader in = new BufferedReader(new InputStreamReader(
                  url.openStream()));
          in.readLine(); // Forward Header
          while (true) {
              String thisLine = in.readLine();
              if (thisLine == null) {
                  break;
              }
              String[] separatedLine = thisLine.split("[,X]"); // split by commas
              adjclose.add(Double.parseDouble(separatedLine[6]));
              System.out.println(adjclose.get(counter) + " " + counter);
              counter = counter + 1;
          }
          return adjclose;
      } catch (IOException e) {
          return null;
      }
  }
  </code></pre>
  
  <p>I have now made the changes to the code within the first class and it appears as follows.</p>
  
  <pre><code>package yahooapi;
  
  /**
   *
   * @author RSLOMA
   */
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.net.URL;
  import java.util.ArrayList;
  import java.util.Calendar;
  
  public class YahooAPI {
  
  
  int startMonth;
  int startDay;
  int startYear;
  
  int endMonth;
  int endDay;
  int endYear;
  int TodayDate;
  
  String freq;
  
  public ArrayList&lt;Double&gt; data = new ArrayList&lt;&gt;();
  
  
  public ArrayList&lt;Double&gt;  getAdjClose(String symbol) throws IOException {
  String baseUrl = "http://ichart.finance.yahoo.com/table.csv?ignore=.csv";
  baseUrl += "&amp;s=" + symbol;
  baseUrl += "&amp;a=" + startMonth;
  baseUrl += "&amp;b=" + startDay;
  baseUrl += "&amp;c=" + startYear;
  baseUrl += "&amp;d=" + endMonth;
  baseUrl += "&amp;e=" + endDay;
  baseUrl += "&amp;f=" + endYear;
  baseUrl += "&amp;g=" + freq;
  
  URL url;
  
  // use a local variable
  
  ArrayList&lt;Double&gt; adjclose = new ArrayList&lt;&gt;(); 
  
  System.out.print("Opening URL: ");
  System.out.print(baseUrl);
  System.out.println(" ");
  
  int counter = 0;
  
  try {
  url = new URL(baseUrl);
  BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
  
  in.readLine(); //Forward Header
  
  while (true){
  String thisLine = in.readLine();
  if (thisLine == null){
  break;
  }
  String[] separatedLine = thisLine.split("[,X]"); // split by commas
  
  adjclose.add(Double.parseDouble(separatedLine[6]));
  System.out.println(adjclose.get(counter) + " " + counter);
  
  // update the data once the read is done
  
  data = adjclose;
  System.out.println(data.get(counter));
  
  counter = counter + 1;
  
  }
  
  
  return adjclose;
  
  } catch (IOException e) {
      return null;
  }
  }
  
  
  public static void main(String args[]) throws IOException{
  YahooAPI y = new YahooAPI();
  Calendar cal = Calendar.getInstance();
  
  y.startDay = 1;
  y.startMonth = cal.get(Calendar.MONTH) - 1; //0 is jan, so 2 is march
  y.startYear = cal.get(Calendar.YEAR) - 3;
  System.out.println("Day: " + y.startMonth);
  System.out.println("Day: " + y.startDay);
  System.out.println("Day: " + y.startYear);
  
  y.endDay = cal.get(Calendar.DATE) - (cal.get(Calendar.DATE) - 1);
  y.endMonth = cal.get(Calendar.MONTH); //0 is jan, so 2 is march
  y.endYear = cal.get(Calendar.YEAR);
  
  y.freq = "m"; // d for daily frequency, w for weekly, m for monthly
  
  ArrayList&lt;Double&gt; adjclose = y.getAdjClose("^GSPC");
  
  //Iterator&lt;Double&gt; iter = adjclose.iterator();
  
  //System.out.println("Returned Adjusted Close Values:");
  //while (iter.hasNext()){
  //System.out.println(iter.next());
  
  
  int ArrayLngth = adjclose.size();
  
  System.out.print("Array length = " + ArrayLngth + "    ");
  }
  
      public ArrayList&lt;Double&gt; getAdjClose() {
  
          for (int counter = 0; counter&lt;data.size(); counter++) {
  
              System.out.println(data.get(counter) + " " + counter);
  
      }
  
  
  
          return (ArrayList&lt;Double&gt;) data.clone();
  
  
      }
  
  
  
  }
  </code></pre>
  
  <p>I have another class in another package that I want to use for calculations, retain the original data elements in the original array, and save the new calculated data in an array in the 2nd class.  The beginning code for the other class is below.  How do I call to obtain the data that is cloned in data.clone()?</p>
  
  <pre><code>package PortfolioDesign;
  
  /**
   *
   * @author RSLOMA
   */
  
  
  public class MonthlyReturns {
  
  
          }
  </code></pre>