title: Java - Implementing sorting algorithms the 'right' way
body: <p>I'm currently playing with implementing various sorting algorithms in Java, mostly for fun, but I'm struggling with how to do it 'right'. That is, I want the user to be able to call the sorting algorithm of choice on anything that is comparable - <code>int</code>s, <code>long</code>s, <code>String</code>s, <code>boolean</code>s (actually, are these comparable in Java?), their own classes; whatever. The question is how to do this.</p>
  <p>I was thinking of using a class to represent the sorting algorithm, and therefore store the things to be sorted inside using a generic list or whatever (<code>List&lt;E&gt;</code>). This would also allow me to use multiple constructors and thus allow the user to pass in the data in various forms - Lists, Arrays, whatever. Is this the correct way to do it? My current problem is that I don't wish for the user to have to create a class when they want to sort something, I'd rather it was able to be called much like <code>System.out.println</code> or the like.</p>
  <pre><code>// Example:
  
  int[] myInts = {5,4,3,2,1};
  
  // This is what I do *not* want.
  InsertionSort mySort = new InsertionSort();
  int[] sortedInts = mySort.sort(myInts);
  
  // This is more like what I want.
  int[] sortedInts = Sorting.insertionSort(myInts);
  </code></pre>
  <p>I apologise with what may seem like a basic question, but I am just learning my way with programming languages. Which is a bit ridicolous for a 2<sup>nd</sup> year Computing student working at a software company for his summer job, but you'd be surprised at how little <em>programming</em> knowledge is required for most of my work... it's usually more design knowledge.</p>
  <h2>EDIT:</h2>
  <p>For clarity, my three main question are:</p>
  <ul>
  <li>Is it better to have the user create a class to do the sorting, or to have a static method in a class the user imports?</li>
  <li>Is it possible to deal with both primitive data types and generic objects easily? Since I want to be able to handle any generic object that implements comparable (or likewise), this then causes problems with primitives (as they don't implement anything ;) ).</li>
  <li>What is the best way to handle generic input - what should I check for before I try to sort them (implementing Comparable, for example)?</li>
  </ul>