title: Sorting (names) using Merge Sort
body: <p>having problem sorting repeated Strings, </p>
  
  <p>and here's my code..</p>
  
  <p>i successfully sorted the first array but in the second (with repeated strings) it seems not in orderly output, can you help me to trace whats wrong in my code..</p>
  
  <pre><code>import java.util.*;
  
  public class NewClass {
      public static void main(String[] args) {
          String[] ClassOne = { "Kring", "Panda", "Soliel", "Darryl", "Chan", "Matang", "Jollibee.", "Inasal" };
          String[] ClassTwo = { "Minnie", "Kitty", "Madonna", "Miley", "Zoom-zoom", "Cristine", "Bubbles", "Ara", "Rose", "Maria" };
          String[] names = new String[ClassOne.length + ClassTwo.length];
  
          mergeSort(ClassOne);
          mergeSort(ClassTwo);
  
          merge(names, ClassOne, ClassTwo);
  
          mergeSort(names);
          //Arrays.sort(names);
  
          for (String ClassThree : names) {
              System.out.println(ClassThree);
          }
      }
  
      public static void mergeSort(String[] names) {
          if (names.length &gt; 2) {
              String[] left = new String[names.length / 2];
              String[] right = new String[names.length - names.length / 2];
  
              for (int i = 0; i &lt; left.length; i++) {
                  left[i] = names[i];
              }
  
              for (int i = 0; i &lt; right.length; i++) {
                  right[i] = names[i + names.length / 2];
              }
  
              mergeSort(left);
              mergeSort(right);
              merge(names, left, right);
          }
      }
  
      public static void merge(String[] names, String[] left, String[] right) {
          int a = 0;
          int b = 0;
          for (int i = 0; i &lt; names.length; i++) {
              if (b &gt;= right.length || (a &lt; left.length &amp;&amp; left[a].compareToIgnoreCase(right[b]) &lt; 0)) {
                  names[i] = left[a];
                  a++;
              } else {
                  names[i] = right[b];
                  b++;
              }
          }
      }
  }
  </code></pre>
  
  <p>and heres the output::</p>
  
  <pre><code>Ara
  Chan
  Cristine
  Bubbles
  Jollibee.
  Inasal
  Kring
  Madonna
  Matang
  Miley
  Minnie
  Kitty
  Panda
  Rose
  Maria
  Soliel
  Darryl
  Zoom-zoom
  </code></pre>
  
  <p>...</p>