title: How to Sort 2D ArrayList<String> by Only the First Element
body: <p><strong>To avoid the duplicate claims</strong>, I've looked at <a href="https://stackoverflow.com/questions/1512366/java-2d-arraylist-and-sorting">this</a> post and it isn't exactly what I wanted. <br> Every other 2D ArrayList question involved <code>double</code> or <code>int</code> numbers; my question is about <code>Strings</code>. </p>
  
  <h3>What I'm doing</h3>
  
  <p>I have a 2D ArrayList, defined like this:</p>
  
  <pre class="lang-java prettyprint-override"><code>ArrayList&lt;ArrayList&lt;String&gt;&gt; namesAndNumbers = new ArrayList&lt;ArrayList&lt;String&gt;&gt;();
  </code></pre>
  
  <p>The idea is that the first item in every row of ArrayLists contains the names, and the rest of the columns in each row contains the phone numbers (unknown amount). Therefore I would like to avoid converting it to a regular array.</p>
  
  <h3>Sample</h3>
  
  <p>Let's say I've populated my ArrayList and I have this:</p>
  
  <pre class="lang-java prettyprint-override"><code>{"Mike", "(805) 766-4920"}
  {"Emily", "(705) 668-9292", "(705) 555-1060"}
  {"James", "(605) 965-2000"}
  </code></pre>
  
  <p>I expect my <strong>output</strong> to be this:</p>
  
  <pre class="lang-java prettyprint-override"><code>{"Emily", "(705) 668-9292", "(705) 555-1060"}    
  {"James", "(605) 965-2000"}
  {"Mike", "(805) 766-4920"}
  </code></pre>
  
  <p>I want to keep the numbers corresponding with the names, but simply sort the array by the name.</p>
  
  <h3>What answers I hope for </h3>
  
  <p>I'm hoping for a built-in function manipulation type of thing, but I'd be fine if someone created a sorting array method for me with an 2D ArrayList as the input. I haven't seen any question that answers this issue explicitly. <em>I will continue trying to come up with an answer myself as well</em>.</p>