So I'm trying to read some numbers from a file and put them into an array. I've been reading about people having problems with whitespace, so using trim, I did it like this:
String[] tokens = new String[length];
for(int i = 0; i<length;i++){
String line = fileReader.nextLine();
line = line.trim();
tokens = line.split("");
}
But the first element this array (token[0]) becomes empty. Am I using the split function wrong?
split(...)
is the (regex) delimiter. So if your input is eg.1, 2, 4, 8
you could dosplit( "," )
.' – Anders R. Bystrup Apr 19 '13 at 10:42