Why does the split method not return an array with 2 elements?
for(int i = 0; i < temparray.size(); i++)
{
if (temparray.get(i).contains("_"))
System.out.println("True" + temparray.get(i).length() + " " + temparray.get(i));
String[] temp = temparray.get(i).split("_");
System.out.println(temp[0]);
//System.out.println(temp[1]);
//friendsOld.add(new Friend(temp[0],temp[1]));
}
If I uncomment either of the lines, I get ArrayOutofBoundsException: 1. The println always returns True, the length of the String, and then a String with _ located within the String - NOT at the end.
I've tried negative parameters for .split(), converting the String to char arrays and breaking the String using indexOf() to find the location of _ then splitting it manually using substring(). There might be something wrong with the String itself but here is the code for the array of Strings: ArrayList<String> temparray = new ArrayList<String>();.
_is never at the end so the trailing string isn't empty. Correct?