title: Java sort based on keywords
body: <p>I have a list of vehicles. I want to sort theses vehicles based on the make. Order is deined in another array. </p>
  
  <p>This code sorts well with an array of two makes, "Honda" and "Kia". This sorts with Honda on top of Kia on top of the rest. Is it possible to make it generic for an array that would change in size. What if the array was "Chevrolet","Dodge","Ford"?</p>
  
  <p>Thanks</p>
  
  <pre><code>//This sorts Honda first, Kia second, and others after.
  final String[] makes = new String[]{"Honda","Kia"};
  Collections.sort(vehicles, new Comparator&lt;Vehicle&gt;() {
      @Override
      public int compare(Vehicle o1, Vehicle o2) {
          String makeObj1 = o1.getModel().getMakeName().toLowerCase();
          String makeObj2 = o2.getModel().getMakeName().toLowerCase();
          //honda first
          if (makeObj1.equals(makes[0].toLowerCase())) {
              if (makeObj2.equals(makes[0].toLowerCase())) {
                  return 0;//honda = honda
              }
              if (makeObj2.equals(makes[1].toLowerCase())) {
                  return -1;//honda &gt; kia
              } else {
                  return -1;//honda &gt; others
              }
          }
          //kia first
          if (makeObj1.equals(makes[1].toLowerCase())) {
              if (makeObj2.equals(makes[0].toLowerCase())) {
                  return 1;//kia &lt; honda
              }
              if (makeObj2.equals(makes[1].toLowerCase())) {
                  return 0;//kia = kia
              } else {
                  return -1;//kia &gt; others
              }
          }
          //honda second
          if (makeObj2.equals(makes[0].toLowerCase())) {
              if (makeObj1.equals(makes[1].toLowerCase())) {
                  return 1;//kia &lt; honda
              } else {
                  return 1;//other &lt; honda
              }
          }
          //kia second
          if (makeObj2.equals(makes[1].toLowerCase())) {
              return 1;//others &lt; kia
          }
          return 0;//all cases should been covered
      }
  });
  </code></pre>