Я немного запуталсяКак правильно разбить строку в Java
public static void main(String [] args){
String s = "a,b,c,d,";
System.out.println(s.split(",").length);
}
Я ожидал увидеть 5 как выход .. но выход 4? Почему он игнорирует последнее поле «null»
Как обработать этот случай, если я пытаюсь разобрать данные, которые имеют (скажем) 5 столбцов.
cases:
a,b,c,d,e
a,,c,d,e //this case is fine as this still has 5 fields.. one of the field is missing.. but thats ok
a,b,c,d //simple length check with header catches this error
a,b,c,d,e,f //simple length check
a,b,c,d,e,// looks like there are 6 fields.. but unable to catch such error by length check
Строка 'null' отличается от пустой (" ") строки. – Prateek