I am trying to find the index of a value in a nested ArrayList, but I need to find the position of the first ArrayList. I am receiving an error when I run this code:
public int findCity(String city) {
city = "\"" + city + "\"";
System.out.println(cityArray.size());
for (List<String> value : cityArray) {
String newCity = value.get(1);
if (newCity == city) return cityArray.indexOf(value);
}
return -1;
}
The problem happens in the line after the for loop:
String newCity = value.get(1);
It's telling me that index 1 is out of bounds for length 1. Any help is greatly appreciated!
I found the problem: I was using nextLine() to read the csv file, and it was creating a new array every time there was a space. This was a huge oversight on my part, but now I can start fixing the problem.
Once again, sorry for the inconvinience.