1. <i id='Vza8K'><tr id='Vza8K'><dt id='Vza8K'><q id='Vza8K'><span id='Vza8K'><b id='Vza8K'><form id='Vza8K'><ins id='Vza8K'></ins><ul id='Vza8K'></ul><sub id='Vza8K'></sub></form><legend id='Vza8K'></legend><bdo id='Vza8K'><pre id='Vza8K'><center id='Vza8K'></center></pre></bdo></b><th id='Vza8K'></th></span></q></dt></tr></i><div id='Vza8K'><tfoot id='Vza8K'></tfoot><dl id='Vza8K'><fieldset id='Vza8K'></fieldset></dl></div>

      <small id='Vza8K'></small><noframes id='Vza8K'>

      <legend id='Vza8K'><style id='Vza8K'><dir id='Vza8K'><q id='Vza8K'></q></dir></style></legend>

        <bdo id='Vza8K'></bdo><ul id='Vza8K'></ul>
      <tfoot id='Vza8K'></tfoot>
    1. Integer.parseInt(String str) java.lang.NumberFormatException:

      时间:2023-09-30

            • <bdo id='ZBRuK'></bdo><ul id='ZBRuK'></ul>

            • <i id='ZBRuK'><tr id='ZBRuK'><dt id='ZBRuK'><q id='ZBRuK'><span id='ZBRuK'><b id='ZBRuK'><form id='ZBRuK'><ins id='ZBRuK'></ins><ul id='ZBRuK'></ul><sub id='ZBRuK'></sub></form><legend id='ZBRuK'></legend><bdo id='ZBRuK'><pre id='ZBRuK'><center id='ZBRuK'></center></pre></bdo></b><th id='ZBRuK'></th></span></q></dt></tr></i><div id='ZBRuK'><tfoot id='ZBRuK'></tfoot><dl id='ZBRuK'><fieldset id='ZBRuK'></fieldset></dl></div>
            • <legend id='ZBRuK'><style id='ZBRuK'><dir id='ZBRuK'><q id='ZBRuK'></q></dir></style></legend>

                  <tbody id='ZBRuK'></tbody>
              1. <tfoot id='ZBRuK'></tfoot>

                <small id='ZBRuK'></small><noframes id='ZBRuK'>

                本文介绍了Integer.parseInt(String str) java.lang.NumberFormatException: 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                I keep getting number format expectations, even though I'm trimming the strings and they don't contain non numerical characters bizarrely it works for some numbers and not others. Below is an example of a string I get number format exception for. Also, any string starting with 0 e.g "0208405223", is returned 208405223, there's no zero anymore is that supposed to happen?

                String n="3020857508";
                Integer a = Integer.parseInt(n.trim());
                System.out.println(a);
                

                This is the exception:

                Exception in thread "main" java.lang.NumberFormatException: For input string: "3020857508"
                    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
                    at java.lang.Integer.parseInt(Integer.java:583)
                    at java.lang.Integer.parseInt(Integer.java:615)
                    at JavaBeans.Main.main(Main.java:15)
                

                解决方案

                It's because 3020857508 exceeds Integer.MAX_VALUE. You should use long to convert the string to number.

                java> String n="3020857508";
                //=> java.lang.String n = "3020857508"
                java> Integer a = Integer.parseInt(n.trim());
                //=> java.lang.NumberFormatException: For input string: "3020857508"
                java> Integer.MAX_VALUE
                //=> java.lang.Integer res2 = 2147483647
                java> Long a = Long.parseLong(n.trim());
                //=>java.lang.Long a = 3020857508
                

                The above is javarepl output.

                If you are using JDK9 or above, you can see the same result in jshell.

                jshell> String n="3020857508"
                n ==> "3020857508"
                
                jshell> Integer a = Integer.parseInt(n.trim())
                |  Exception java.lang.NumberFormatException: For input string: "3020857508"
                |        at NumberFormatException.forInputString (NumberFormatException.java:65)
                |        at Integer.parseInt (Integer.java:652)
                |        at Integer.parseInt (Integer.java:770)
                |        at (#2:1)
                
                jshell> Integer.MAX_VALUE
                $3 ==> 2147483647
                
                jshell> Long a = Long.parseLong(n.trim());
                a ==> 3020857508
                

                这篇关于Integer.parseInt(String str) java.lang.NumberFormatException: 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:带有数学运算符的字符串到整数 下一篇:将 BigDecimal 转换为 Integer

                相关文章

                最新文章

                <legend id='MaPo8'><style id='MaPo8'><dir id='MaPo8'><q id='MaPo8'></q></dir></style></legend>

                  • <bdo id='MaPo8'></bdo><ul id='MaPo8'></ul>

                1. <i id='MaPo8'><tr id='MaPo8'><dt id='MaPo8'><q id='MaPo8'><span id='MaPo8'><b id='MaPo8'><form id='MaPo8'><ins id='MaPo8'></ins><ul id='MaPo8'></ul><sub id='MaPo8'></sub></form><legend id='MaPo8'></legend><bdo id='MaPo8'><pre id='MaPo8'><center id='MaPo8'></center></pre></bdo></b><th id='MaPo8'></th></span></q></dt></tr></i><div id='MaPo8'><tfoot id='MaPo8'></tfoot><dl id='MaPo8'><fieldset id='MaPo8'></fieldset></dl></div>

                  <tfoot id='MaPo8'></tfoot>

                    <small id='MaPo8'></small><noframes id='MaPo8'>