title: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
body: <p>Like the title says, my problem is that when I compile I get Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1. Here is the part where the problem is coming from.</p>
  
  <p>Edit. </p>
  
  <pre><code>Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1   
  at java.util.ArrayList.rangeCheck(ArrayList.java:653)   
  at java.util.ArrayList.get(ArrayList.java:429)  
  at pa6.FlightFinder.bestDirectPrice(FlightFinder.java:117)  
  at pa6.FlightFinder.main(FlightFinder.java:14)
  
  
  public static ArrayList&lt;String&gt; bestDirectPrice(ArrayList&lt;String&gt; flightList,String city1, String city2) {
  ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();
  ArrayList&lt;String&gt; Price = new ArrayList&lt;String&gt;();
  for (int i=0; i&lt;flightList.size(); i++) {
      list = directFlights(flightList, city1, city2);
      Price.add(getPrice(list.get(i)));
  
  }
  return Price;
  </code></pre>
  
  <p>I've been searching online for a solution, so I'm pretty sure the problem is that the array is too small, but i'm still not sure how to fix it. I'm trying to get the upper part of code to take just the numbers out of the array and put them in a new one.</p>
  
  <pre><code>ArrayList&lt;String&gt; test = new ArrayList&lt;String&gt;(); //Array with list of flights
  test.add("Orlando#DesMoines#194.88");
  test.add("Portland#Orlando#287.74");
  test.add("Buffalo#Boston#299.52"); 
  test.add("Buffalo#Portland#264.80"); 
  test.add("Chicago#Buffalo#223.56");
  
  System.out.println(bestDirectPrice(test,"Buffalo","Orlando"));
  </code></pre>
  
  <p>And here are the other methods I'm calling.</p>
  
  <pre><code>public static String getPrice(String price) { //Takes flight description, which is a string, as a parameter and returns price of flight
  String[] sArray = price.split("#", -1);
  String newPrice = "";
  for (int i = 0; i&lt;1; i++)       
      newPrice = sArray[2];
  return newPrice;
  }
  
  public static ArrayList&lt;String&gt; directFlights(ArrayList&lt;String&gt; flightList, String city1, String city2) { // Method to create array list containing every direct flight from city1 to city 2
  ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();
  for (int i=0; i&lt;flightList.size(); i++){
      String city2a = getDestinationCity(flightList.get(i));
      String city1a = getOriginationCity(flightList.get(i));
      if (city1a.equals(city1) &amp;&amp; city2a.equals(city2)) {
          list.add(flightList.get(i));
      }
  }
  return list;
  }
  </code></pre>
  
  <p>I've been stuck on this for awhile so any help would be greatly appreciated!</p>
  
  <p>Edit. </p>
  
  <pre><code>Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1   
  at java.util.ArrayList.rangeCheck(ArrayList.java:653)   
  at java.util.ArrayList.get(ArrayList.java:429)  
  at pa6.FlightFinder.bestDirectPrice(FlightFinder.java:117)  
  at pa6.FlightFinder.main(FlightFinder.java:14)
  </code></pre>