「Java」parseIntメソッドで文字列を数値に変換する
環境
JDK1.8
Eclipse2019
書式
public static int parseInt(String s) throws NumberFormatException
パラメータ
s:解析対象のint表現を含むString
戻り値:10進数の引数で表される整数値
使用例
package com.arkgame.Test;
public class StrToIntDemo {
public static void main(String[] args) {
String str = "1234";
int num = Integer.parseInt(str);
System.out.println(num);
}
}
package com.arkgame.Test;
public class StrToIntDemo {
public static void main(String[] args) {
String str = "1234";
int num = Integer.parseInt(str);
System.out.println(num);
}
}
package com.arkgame.Test; public class StrToIntDemo { public static void main(String[] args) { String str = "1234"; int num = Integer.parseInt(str); System.out.println(num); } }
結果
1234