Long类decode()方法在java.lang包中提供了define ()方法。
encode()方法用于将给定的String值解码为Long值。
encode()方法是一个静态方法,也可以使用类名进行访问,如果尝试使用类对象访问该方法,则也不会出错。
在将String解码为Long时,decode()方法可能会引发NumberFormatException。
NumberFormatException:在此异常中,如果给定的字符串参数没有可解析的整数。
语法:public static Long decode(String str);
参数:字符串str –表示要解码的字符串。
返回值:
此方法的返回类型为long,它返回Long,其中Long持有由String类型的参数表示的long值。
示例//Java程序演示示例
//类的decode(String str)方法的说明
public class DecodeOfLongClass {
public static void main(String[] args) {
//变量初始化
long l = 100;
String str = "20";
//长对象初始化为“长”值"long" value
Long ob1 = new Long(l);
//显示ob1结果
System.out.println("ob1: " + ob1);
//它返回一个持有long值的Long对象
//由给定的String参数表示
//ob1.decode(str)
Long result = ob1.decode(str);
//显示结果
System.out.println("ob1.decode(str) :" + result);
}
}
输出结果ob1: 100
ob1.decode(str) :20