0

I want to take each Twitter status and split them into individual words and store them in an ArrayList called terms. I'm trying to use the split() method as I've been told that split() can help me separate a String sentence into individual words nicely into an array, but I seem to be running into an error (IndexOutOfBoundsException) and I'm not sure why, because I can't seem to find the source of error/error line from the Run I/O.

private List<Status> statuses;
private List<String> terms;

public void splitIntoWords()
      {
         for (Status thisStatus: statuses)
         {
            String temp = thisStatus.getText(); 
            System.out.println(temp); 
            String[] arr = temp.split(" ");
            for(int i = 0; i<arr.length; i++)
            {
               terms.add(arr[i]); 
            }
         }
      }
singularity
  • 211
  • 1
  • 8
  • 1
    you can use `Arrays.asList()`. The code looks ok. did you try to [debug](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems?noredirect=1&lq=1) it? a calls stack would indicate the faulty line. sample input to reproduce the behavior would be good. – Curiosa Globunznik Dec 09 '19 at 00:44
  • Which line is throwing the OutOfBoundsException? – Ryan Russell Dec 09 '19 at 01:29
  • Does not look like it is in this code. – Scary Wombat Dec 09 '19 at 01:29

0 Answers0