在 Java 中将字符串转换为数字以及相反操作。
Java lang 包提供了 Integer 类,其中包含用于将整数转换为字符串以及相反操作的方法。你可以使用 parseInt() 方法将字符串转换为整数,使用 toString() 方法将整数转换为字符串。
示例
public class Sample {
public static void main(String args[]){
String str = "1212";
int num = Integer.parseInt(str);
System.out.println(num);
String st = Integer.toString(num);
System.out.println();
}
}输出
1212
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
JavaScript
PHP