title: What's the best way to check if a String represents an integer in Java?
body: <p>I normally use the following idiom to check if a String can be converted to an integer.</p>
  
  <pre><code>public boolean isInteger( String input ) {
      try {
          Integer.parseInt( input );
          return true;
      }
      catch( Exception e ) {
          return false;
      }
  }
  </code></pre>
  
  <p>Is it just me, or does this seem a bit hackish?  What's a better way?</p>
  
  <hr>
  
  <p>See my answer (with benchmarks, based on the <a href="https://stackoverflow.com/a/237321/1288">earlier answer</a> by <a href="https://stackoverflow.com/users/28278/codingwithspike">CodingWithSpike</a>) to see why I've reversed my position and accepted <a href="https://stackoverflow.com/a/237204/1288">Jonas Klemming's answer</a> to this problem.  I think this original code will be used by most people because it's quicker to implement, and more maintainable, but it's orders of magnitude slower when non-integer data is provided.</p>