本文共 3116 字,大约阅读时间需要 10 分钟。
Syntax:
句法:
public static byte parseByte(String str); public static byte parseByte(String str, int radix's);
parseByte() method is available in java.lang package.
parseByte()方法在java.lang包中可用。
parseByte(String str) method is used to return the byte value corresponding to the given String denotation or in other words we can say this method is used to convert string value to a byte value.
parseByte(String str)方法用于返回与给定String表示形式相对应的字节值,换句话说,我们可以说此方法用于将字符串值转换为字节值。
parseByte (String str, int radix's) method is used to return the byte value corresponding to the given String denotation as a signed byte in the radix's given by the second argument.
parseByte(String str,int radix's)方法用于返回与给定String表示形式对应的字节值,作为第二个参数给定的基数中的有符号字节。
parseByte(String str), parseByte(String str, int radix's) method may throw a NumberFormatException at the time of conversion from String to byte.
从字符串到字节的转换时, parseByte(String str) , parseByte(String str,int radix's)方法可能会引发NumberFormatException。
NumberFormatException: In this exception, if String does not contain the parsable number.
NumberFormatException:在此异常中,如果String不包含可分析的数字。
These are static the methods, they are accessible with the class name too and, if we try to access these methods with the class object then also we will not get an error.
这些是静态方法,它们也可以通过类名进行访问,而且,如果我们尝试使用类对象访问这些方法,那么也不会出错。
Parameter(s):
参数:
In the first case, String value – represents the value of String type.
在第一种情况下, 字符串值 –表示字符串类型的值。
In the second case, String value, int radix's – In this method first parameter value represent the value of String type in the radix's given by the second parameter.
在第二种情况下, String值,int radix's –在此方法中,第一个参数值表示第二个参数给定的基数中String类型的值。
Return value:
返回值:
In the first case, the return type of this method is byte - it returns the byte representation of this String argument.
在第一种情况下,此方法的返回类型为byte-它返回此String参数的字节表示形式。
In the second case, the return type of this method is byte - it returns the byte representation of the String argument in the radix's given by the second argument.
在第二种情况下,此方法的返回类型为byte-它以第二个参数给定的基数形式返回String参数的字节表示形式。
Example:
例:
// Java program to demonstrate the example // of parseByte() method of Byte classpublic class ParseByteOfByteClass { public static void main(String[] args) { // Variables initialization String str1 = "100"; String str2 = "67"; int radix = 10; // Object initialization Byte b1 = new Byte(str2); // It convert string into byte by calling parseByte(str1) method // and store the result in another variable of byte type byte result = b1.parseByte(str1); // Display result System.out.println("b1.parseByte(str1): " + result); // It convert string into byte with radix 20 by calling parseByte(str1,radix's) method // and store the result in a variable of byte type result = b1.parseByte(str1, radix); // Display result System.out.println("b1.parseByte(str1,radix): " + result); }}
Output
输出量
b1.parseByte(str1): 100b1.parseByte(str1,radix): 100
翻译自:
转载地址:http://dpvzd.baihongyu.com/