title: Sorting array with null values
body: <p>I have a program that allows user to delete an element from an array and I am trying to sort them in alphabetic order using compareTo(); through a for loop. However, the null values are giving me problems. For example an array with null values:</p>
  
  <pre><code>String[] myArray = {"Apple", "Banana", null, "Durian", null, null, "Grapes"};
  </code></pre>
  
  <p>When Java is comparing them and reads a null value, it would give me a NullPointerException.</p>
  
  <p>Is there any way that I can sort this array with null values at the back? For example:</p>
  
  <pre><code>{"Apple", "Banana", "Durian", "Grapes", null, null, null}
  </code></pre>
  
  <p>I know that using Vectors can solve the problem but I am just curious if there is any way that I can just do it without changing my array to vectors.</p>