title: Java ArrayList strings lengths printing
body: <p>My excercise is:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>And my code:</p>
  
  <pre><code>import java.util.ArrayList;
  
  public class Test {
  
  public static ArrayList&lt;Integer&gt; lengths(ArrayList&lt;String&gt; strings) {
          ArrayList&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();
  
          for (String item : strings) {
              System.out.print(item.length());
          }
          return list;
      }
  
  public static void main(String[] args) {
  
  ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();
  
          list.add("Dog");
          list.add("Elephant");
          list.add("Aligator");
          list.add("Parrot");
  
          ArrayList&lt;Integer&gt; stringLenghts = lengths(list);
          System.out.println(stringLenghts);
  
      }
  }
  </code></pre>
  
  <p>And this program outputs</p>
  
  <blockquote>
    <p>3386[]</p>
  </blockquote>
  
  <p>Instead of</p>
  
  <blockquote>
    <p>[3, 3, 8, 6]</p>
  </blockquote>
  
  <p>Any idea where I do a mistake?</p>