title: How to sort an ArrayList by its elements size in Java?
body: <p>So I have a <code>List&lt;String&gt; L1 = new ArrayList&lt;&gt;()</code> with the following strings as elements:</p>
  
  <ul>
  <li>l, l, u, u.</li>
  <li>r, u, d, l, d, l, u.</li>
  <li>l, u, d, r, r, r, r, r, u, d.</li>
  <li>l, u.</li>
  <li>l, u, r.</li>
  </ul>
  
  <p>How do I sort the <code>list</code> by its element's size so that in the final state L1 should be like this:</p>
  
  <ul>
  <li>l, u.</li>
  <li>l, u, r.</li>
  <li>l, l, u, u.</li>
  <li>r, u, d, l, d, l, u.</li>
  <li>l, u, d, r, r, r, r, r, u, d.</li>
  </ul>
  
  <p>I have tried using <code>Collections.sort</code>, but that sorts alphabetically, which is obviously not what I want.</p>