Proper use of for and if statements in Java/Android
<p>I have an two arrays, one is cityUSA[i] and one is decimalUSA[i].  Each has over 1500 entries, cityUSA[100] goes with decimalUSA[100] and so on.  I find the city people are in via location services in Android and then I compare it to the list of cities I have in the cityUSA[i] array.  I then search for a match and use the i of the match to find the related value of decimalUSA[i] in that array.  Here is the code:</p>

<p>loc.getLatitude();
            loc.getLongitude();
            Geocoder geocoder = new Geocoder(rate.this, Locale.ENGLISH);</p>

<pre><code>        try {
              List&lt;Address&gt; addresses = geocoder.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1);

              TextView rateText = (TextView)findViewById(R.id.taxRate);
              TextView locationText = (TextView)findViewById(R.id.taxLocation);

              if(addresses != null) {
               Address returnedAddress = addresses.get(0);
               String city = returnedAddress.getLocality();
               locationText.setText(city);

                int i;
                for (i = 0; i  &lt;= cityUSA.length; i++){
                    if (cityUSA[i] == city) {
                    String PrecentString = decimalRate[i];
                    rateText.setText(PrecentString);
                    break;
                    }
                }


              }
              else{
                  locationText.setText("No City returned!");
                  rateText.setText("No Rate returned!");
              }


             } 


              catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              TextView locationText = (TextView)findViewById(R.id.Rate);
              locationText.setText("Cannot get Location!");
             }
</code></pre>

<p>The application bombs out when I try to run it.  If I remove the for statment:</p>

<pre><code>                int i;
                for (i = 0; i  &lt;= cityUSA.length; i++){
                    if (cityUSA[i] == city) {
                    String PrecentString = decimalRate[i];
                    rateText.setText(PrecentString);
                    break;
                    }
                }
</code></pre>

<p>It does not bomb out, but then again it does not perform the search either.</p>

<p>Any suggestions?</p>
