Пустой элемент в списке, вызывающий исключение в потоке "main" java.lang.StringIndexOutOfBoundsException: индекс строки вне диапазона - PullRequest
0 голосов
/ 28 мая 2018

Я работаю с CSV-файлом, который выглядит следующим образом https://plus.google.com/u/0/photos/photo/115135191238195349859/6559552907258825106

, как вы можете видеть в колонке "date_sold", есть пробелы

Я пытаюсь сократить даты дотолько месяц (первые два целых числа всей даты с помощью этого метода:

public static void getTotalSales(){

    int w = 0; 
    while (w < date_sold.size()){ 
// if the current element is smaller than the size of the 
        if((date_sold.get(w)) != "" ){ 
// if the element in the array is empty (might be the problem)
      date_sold.set(w,((date_sold.get(w)).substring(0,2)));
// trim the string at the element to two characters
     }
    w = w + 1;
  }
System.out.println(date_sold);
}

Это распечатывает работу для первого элемента от "date_sold" до "da", но затем я получаю

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range

Я хотел бы пропустить пустые элементы, но не избавляться от них, так как для меня важна индексация пустых элементов

...