title: Is there a way to split a String ArrayList based on the names that contains inside of the array?
body: <p>I need to write a Method that receives an ArrayList containing a bunch of person names and then separate this ArrayList into smaller ArrayLists based on the first letter of the name. Names like "Aaron, Albert, Ana" must be put on an ArrayList, "Bart, Bob, Billy" must be on another. Then I need to present an list of a list containing all this smaller lists. The I need to write a JUnit test for this. This was an exercise presented on a beginners Java course :( It's driving me crazy.</p>
  
  <p>I have tried writing "for loops" to check every word for the starting character, but it must be a better way to do this.</p>
  
  <p>This is the list that will be used as parameter to the method:</p>
  
  <pre><code>public List&lt;String&gt; namesList() {
      List&lt;String&gt; names = new ArrayList&lt;String&gt;();
      names.add("ANA");
      names.add("ANA BEATRIX");
      names.add("JOE");
      names.add("WALTER");
      names.add("ROBERT");
      names.add("RODNEY");
      names.add("RUDOLPH");
      names.add("VAGNER");
      names.add("JOSE");
      names.add("CLEITON");
      names.add("MARIA");
      names.add("MARK");
  
      return names;
  }
  </code></pre>
  
  <p>Then I was trying to write the method as follows:</p>
  
  <pre><code>public List&lt;List&lt;String&gt;&gt; separateNames(List&lt;String&gt; names) {
      Collections.sort(names);
      for (String s : name)
      {
         if (s.charAt(0) == 'A') {
             // then create an ArrayList to store names starting with A
         }
  
      }
  }
  </code></pre>
  
  <p>The result should be a list within a list like [["Aaron", "Albert", "Ana"], ["Bart", "Bob", "Billy"... and so on]]</p>