将字符串解码为整数的 Java 程序
Integer.decode() 方法将字符串解码为整数。它返回一个 Integer 对象,其中保存由传递的字符串值表示的 int 值。
注 − 它接受十进制、十六进制和八进制数。
假设以下内容为我们的字符串。
String val = "2";
以下是如何将字符串解码为整数。
Integer myInt = Integer.decode(val);
示例
public class Demo {
public static void main(String []args) {
String val = "2";
Integer myInt = Integer.decode(val);
System.out.println("Integer = " + myInt);
}
}输出
Integer = 2
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP