title: How to sort String array by length using Arrays.sort()
body: <p>I am trying to sort an array of strings according to their length using <code>Arrays.sort()</code>, but this sorts the strings lexicographically rather than by length. Here is my code:</p>
  
  <pre><code>S = "No one could disentangle correctly"
  String W[] = S.split(" ");
  Arrays.sort(W);
  </code></pre>
  
  <p>After sorting :</p>
  
  <pre><code>correctly
  could
  disentangle
  no
  one
  </code></pre>
  
  <p>but what I want is </p>
  
  <pre><code>no  //length = 2
  one //length = 3
  could //length = 4 and likewise
  correctly
  disentangle
  </code></pre>
  
  <p>How can I get the above output? Please give answer for JDK 1.7 &amp; JDK1.8.</p>