Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 4, Size: 4 : ... at java.util.ArrayList.rangeCheck(ArrayList.java:657)
	
at java.util.ArrayList.get(ArrayList.java:433)
	
at LengthsOfStrings.lengths(LengthsOfStrings.java:11)
	
at LengthsOfStrings.main(LengthsOfStrings.java:26)

**The exercise question:**

Create the method `lengths` that gets a list of String variables as a parameter and returns an ArrayList that contains the lengths of the Strings in the same order as the original list.

The output of the given objects should be:
`The lengths of the Strings: [5, 3, 10, 27]`

**My code:**

    import java.util.ArrayList;

    public class LengthsOfStrings {
    
    public static ArrayList<Integer> lengths(ArrayList<String> list) {
        ArrayList<Integer> lengthList = new ArrayList<Integer>();
        
        int count = 0;
        
        for (String word : list) {
            for (int x = 0; x < ( list.get(x) ).length(); x++) {
                count++;
            }
            lengthList.add(count);
            count = 0;
        }
        return lengthList;
    }

    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<String>();
        list.add("Ciao");
        list.add("Moi");
        list.add("Benvenuto!");
        list.add("badger badger badger badger");
        ArrayList<Integer> lengths = lengths(list);
        
        System.out.println("The lengths of the Strings: " + lengths);
        
    }
    }