「Java」parseIntメソッドで文字列を数値に変換する

2022年4月7日

環境
JDK1.8
Eclipse2019

書式
public static int parseInt(String s) throws NumberFormatException
パラメータ
s:解析対象のint表現を含むString
戻り値:10進数の引数で表される整数値

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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

Java

Posted by arkgame