用法:
public static byte parseByte(String str); public static byte parseByte(String str, int radix's);
Short类parseByte()方法
- parseByte() 方法可在
java.lang
包。 - parseByte(String str) 方法用于返回与给定字符串表示对应的字节值,或者换句话说,我们可以说这个方法用于将字符串值转换为字节值。
- parseByte (String str, int radix's) 方法用于返回与给定字符串表示对应的字节值,作为第二个参数给出的基数中的有符号字节。
- parseByte(String str), parseByte(String str, int radix's) 方法在从 String 转换为 byte 时可能会抛出 NumberFormatException。NumberFormatException:在此异常中,如果 String 不包含可解析的数字。
- 这些是静态的方法,它们也可以通过类名访问,如果我们尝试使用类对象访问这些方法,那么我们也不会得到错误。
参数:
- 在第一种情况下,
String value
– 表示 String 类型的值。 - 在第二种情况下,
String value, int radix's
– 在这个方法中的第一个参数value
表示 String 类型中的值radix's
由第二个参数给出。
返回值:
在第一种情况下,该方法的返回类型是byte
- 它返回此字符串参数的字节表示。
第二种情况,这个方法的返回类型是byte
- 它以第二个参数给出的基数返回字符串参数的字节表示。
例:
// Java program to demonstrate the example
// of parseByte() method of Byte class
public 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);
}
}
输出
b1.parseByte(str1):100 b1.parseByte(str1,radix):100
相关用法
- Java Byte parseByte()用法及代码示例
- Java Byte valueOf()用法及代码示例
- Java Byte floatValue()用法及代码示例
- Java Byte hashCode()用法及代码示例
- Java Byte compareTo()用法及代码示例
- Java Byte toString()用法及代码示例
- Java Byte decode()用法及代码示例
- Java Byte longValue()用法及代码示例
- Java Byte compare()用法及代码示例
- Java Byte equals()用法及代码示例
- Java Byte byteValue()用法及代码示例
- Java Byte intValue()用法及代码示例
- Java Byte shortValue()用法及代码示例
- Java Byte compareUnsigned()用法及代码示例
- Java Byte toUnsignedInt()用法及代码示例
- Java Byte doubleValue()用法及代码示例
- Java Byte toUnsignedLong()用法及代码示例
- Java ByteArrayInputStream markSupported()用法及代码示例
- Java ByteBuffer isDirect()用法及代码示例
- Java ByteBuffer compareTo()用法及代码示例
注:本文由纯净天空筛选整理自Preeti Jain大神的英文原创作品 Java Byte class parseByte() method with example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。