title: Sort strings in an array based on length
body: <p>I have the below program for sorting Strings based on length. I want to print the shortest element first. I don't want to use Comparator or any API to do this. Where I am going wrong?</p>
  
  <pre class="lang-java prettyprint-override"><code>public class SortArrayElements {
      public static void main(String[] args) {
          String[] arr = new String[]{"Fan","dexter","abc","fruit","apple","banana"};
          String[] sortedArr = new String[arr.length];
  
          for(int i=0;i&lt;sortedArr.length;i++)
          {           
              sortedArr[i] = compareArrayElements(arr);                       
          }
  
          System.out.println("The strings in the sorted order of length are: ");
          for(String sortedArray:sortedArr)
          {
              System.out.println(sortedArray);
          }
      }
  
      public static String compareArrayElements(String[] arr) {
          String temp = null;
          for(int i=0;i&lt;arr.length-1;i++)
          {
              temp = new String();
              if(arr[i].length() &gt; arr[i+1].length())
                  temp = arr[i+1];
              else
                  temp = arr[i];
          }
          return temp;
      }
  }
  
  </code></pre>