Java17 Integer型をint型に変換するサンプル
環境
JavaSE 17
Eclipse 4.24.0
構文
Integer 変数名 = Integer.valueOf(“数値の文字列");
int 変数名2 = Integer.parseInt(変数名1.toString());
valueOfメソッドを使ってIntgerをintに変換します。
使用例
package com.arkgame.study;
public class ArkgameTest {
public static void main(String[] args) {
Integer cftA = Integer.valueOf("123");
System.out.println("Integer value = " + cftA);
int res = Integer.parseInt(cftA.toString());
System.out.println("int value = " + res);
}
}
実行結果
Integer value = 123
int value = 123