title: compareTo does not work properly
body: <p>I want to sort a input.txt file and save it in output.txt for instance. I use the insertion sort algorithm. Now my problem: the compareTo method seems to work incorrectly (or at least not how I want to to work). It returns integer greater than 1 thus the algorithm does not really especially for negative numbers. I hope you guys can help me with that problem, thanks!</p>
  
  <p>Thats my code: </p>
  
  <pre><code>import java.util.ArrayList;
  import java.io.*;
  
  class Isort
  {
      public static void main(String[] args)
      {   
          if(args[0].equals("int"))
          {
              ArrayList&lt;Integer&gt; array = new ArrayList&lt;Integer&gt;();
              sort(array, args[1], args[2]);
          }
          else if(args[0].equals("float"))
          {
              ArrayList&lt;Float&gt; array = new ArrayList&lt;Float&gt;();
              sort(array, args[1], args[2]);
          }
          else if(args[0].equals("String"))
          {
              ArrayList&lt;String&gt; array = new ArrayList&lt;String&gt;();
              sort(array, args[1], args[2]);
          }
          else
          {
              //do nothing
          }
      }
      public static &lt;T extends Comparable&lt;T&gt;&gt; void sort(ArrayList&lt;T&gt; array, String input, String output)
      {   
          try
          {
              File file = new File(input);
              BufferedReader reader = new BufferedReader(new FileReader(file));       
              reader.mark((int)file.length() + 1); 
              int count = 0;          
              while(reader.readLine() != null)
              {
                  count++;
              }
              reader.reset();
              for(int i = 0; i&lt;count; i++)
              {
                  array.add((T)(reader.readLine()));
              }
              reader.close();
  
              int j;
              T temp;
              for(int i = 1; i &lt; array.size(); i++)
              {
                  j = i;
                  while(j &gt; 0 &amp;&amp; array.get(j-1).compareTo(array.get(j)) &gt; 0)
                  {
                      temp = array.get(j);
                      array.set(j,array.get(j-1));
                      array.set(j-1,temp);
                      j -= 1;
                      System.out.println(array);
                  }
              }
              PrintWriter writer = new PrintWriter(output);
              for(int i = 0; i&lt;array.size(); i++)
              {
                  writer.write(String.valueOf(array.get(i)));
                  writer.write(System.getProperty ("line.separator")); 
              }
              writer.flush();
              writer.close();
          }
          catch(FileNotFoundException e)
          {
  
          }
          catch(IOException e)
          {
              e.printStackTrace();
          }
          catch(Exception ex)
          {
              ex.printStackTrace();
          }
      }
  }
  </code></pre>