「Java」Integer.valueOf(文字列).intValue()で文字列を数値に変換する

2020年11月26日

説明
1.public static Integer valueOf(String s)throws NumberFormatException
指定されたStringの値を保持するIntegerオブジェクトを返します。
2.public int intValue()
このIntegerの値をintとして返します。
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.arkgame.study.cft;
public class InterValueSample {
public static void main(String[] args) {
int res = 0;
String target = "5638";
if ((target != null) && (target.length() > 0)) {
res = Integer.valueOf(target).intValue();
}
System.out.print("文字列->数値: " + res);
}
}
package com.arkgame.study.cft; public class InterValueSample { public static void main(String[] args) { int res = 0; String target = "5638"; if ((target != null) && (target.length() > 0)) { res = Integer.valueOf(target).intValue(); } System.out.print("文字列->数値: " + res); } }
package com.arkgame.study.cft;

public class InterValueSample {

      public static void main(String[] args) {

            int res = 0;
            String target = "5638";
            if ((target != null) && (target.length() > 0)) {
                  res = Integer.valueOf(target).intValue();
            }
            System.out.print("文字列->数値: " + res);
      }

}

結果
文字列->数値: 5638

Java

Posted by arkgame