<bdo id='VZyJM'></bdo><ul id='VZyJM'></ul>

  • <legend id='VZyJM'><style id='VZyJM'><dir id='VZyJM'><q id='VZyJM'></q></dir></style></legend>

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

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

        在Java中将字符转换为整数

        时间:2023-07-27

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

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

                <bdo id='MiUwS'></bdo><ul id='MiUwS'></ul>
                <tfoot id='MiUwS'></tfoot>
              • <legend id='MiUwS'><style id='MiUwS'><dir id='MiUwS'><q id='MiUwS'></q></dir></style></legend>
                  本文介绍了在Java中将字符转换为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  谁能给我解释一下这里发生了什么:

                  Can someone please explain to me what is going on here:

                  char c = '+';
                  int i = (int)c;
                  System.out.println("i: " + i + " ch: " + Character.getNumericValue(c));
                  

                  这将打印 i: 43 ch:-1.这是否意味着我必须依靠原始转换将 char 转换为 int?那么如何将 Character 转换为 Integer?

                  This prints i: 43 ch:-1. Does that mean I have to rely on primitive conversions to convert char to int? So how can I convert a Character to Integer?

                  是的,我知道如果 Character.getNumericValue 不是数值,那么它会返回 -1,这对我来说很有意义.问题是:为什么进行原始转换会返回 43?

                  Yes I know Character.getNumericValue returns -1 if it is not a numeric value and that makes sense to me. The question is: why does doing primitive conversions return 43?

                  Edit2: 43+ 的 ASCII,但我希望转换不会像 getNumericValue 没有成功.否则这意味着有两种语义等效的方式来执行相同的操作但结果不同?

                  43 is the ASCII for +, but I would expect the cast to not succeed just like getNumericValue did not succeed. Otherwise that means there are two semantic equivalent ways to perform the same operation but with different results?

                  推荐答案

                  Character.getNumericValue(c)
                  

                  java.lang.Character.getNumericValue(char ch) 返回指定 Unicode 字符所代表的 int 值.例如,字符 'u216C'(罗马数字 50)将返回一个值为 50 的 int.

                  The java.lang.Character.getNumericValue(char ch) returns the int value that the specified Unicode character represents. For example, the character 'u216C' (the roman numeral fifty) will return an int with a value of 50.

                  字母 AZ 大写 ('u0041' 到 'u005A')、小写 ('u0061' 到 'u007A') 和完整宽度变体 ('uFF21' 到 'uFF3A' 和 'uFF41' 到 'uFF5A') 形式的数值从 10 到 35.这与 Unicode 规范无关,它不为这些 char 值分配数值.

                  The letters A-Z in their uppercase ('u0041' through 'u005A'), lowercase ('u0061' through 'u007A'), and full width variant ('uFF21' through 'uFF3A' and 'uFF41' through 'uFF5A') forms have numeric values from 10 through 35. This is independent of the Unicode specification, which does not assign numeric values to these char values.

                  此方法返回字符的数值,作为非负整数值;

                  This method returns the numeric value of the character, as a nonnegative int value;

                  -2 如果字符的数值不是非负整数;

                  -2 if the character has a numeric value that is not a nonnegative integer;

                  -1 如果字符没有数值.

                  -1 if the character has no numeric value.

                  这里是链接.

                  这篇关于在Java中将字符转换为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                1. <tfoot id='1Av3Q'></tfoot>

                      <tbody id='1Av3Q'></tbody>

                    <small id='1Av3Q'></small><noframes id='1Av3Q'>

                      1. <legend id='1Av3Q'><style id='1Av3Q'><dir id='1Av3Q'><q id='1Av3Q'></q></dir></style></legend>

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