title: How to check a number is out of the range of Integer type?
body: <p>How to check a number is out of the range of Integer?</p>
  
  <p>If the number is greater than <code>Integer.MAX_VALUE</code>, return <code>Integer.MAX_VAlUE</code></p>
  
  <p>If the number is less than <code>Integer.MIN_VALUE</code>, return <code>Integer.MIN_VAlUE</code></p>
  
  <p>EX:
  2000000000000 -> <code>Integer.MAX_VALUE</code></p>
  
  <p>This is my solution, but it seems very inefficient.</p>
  
  <pre><code>if(str.length() &gt;= 10) {
      if(str.charAt(0) != '-') {
          return Integer.MAX_VALUE;
      } else if(str.length() &gt;= 11 &amp;&amp; str.charAt(0) == '-') {
          return Integer.MIN_VALUE;
      }
  }
  </code></pre>