I am using an array of arraylists to store words from a string. I am storing them in the array of array lists by the length of the word. I am using a switch statement right now, but I have to have 45 cases the way I am doing it, and I was wondering if anyone knew of an easier and shorter way that I could carry out the same operation. Here's some code:
String temp;
Scanner sc = new Scanner(str);
while(sc.hasNext())
{
temp = sc.next();
switch(temp.length()){
case 1:
wordsByLen[0].add(temp);
case 2:
wordsByLen[1].add(temp);
case 3:
wordsByLen[2].add(temp);
I have cases 1-45 and a default. I would just like to shorten this up, if possible. Thanks!
List<List<String>>? You'd have to do alistlist.get(i).add(temp)...MultiMap<Integer, String>would be easier to use.