Don't know why I'm getting this error. Working with ArrayLists and sorting words into appropriate ArrayLists by alphabetical order. If anyone can help me understand why I'm getting the error and how to fix it that would be great!
import java.util.*;
public class Sort {
public static ArrayList<Object> sortByFirstLetter( List<String> words) {
ArrayList<Object> bucket = new ArrayList<Object>();
for( int i = 0; i < 26; i++ ) {
ArrayList<String> letter = new ArrayList<String>();
bucket.add(letter);
}
for( String word : words ) {
int index = (int)(word.toLowerCase().charAt(0)) - 97; //get a number 0-25 for index; 97 is unicode for lwrcse "a"
System.out.println(index);
bucket.get(index).add(str); //THIS LINE GIVES ERROR
}
return bucket;
}
public static void main(String[] args) {
List<String> words = Arrays.asList("alex", "andy", "kevin");
sortByFirstLetter( words );
}
}
Object, which is nonsensical.