LoginSignup
3
4

More than 5 years have passed since last update.

JAVA IntegerクラスのparseInt() toHexString() valueOf()メソッド

Last updated at Posted at 2015-11-12

toHexString() 整数を16進数表現に変換する

toHexString()の例 
        int nn = 43;
        String n2 = Integer.toHexString(nn);
        System.out.println(n2);

実行結果
2b
toHexString()の例② 
        String n2 = Integer.toHexString(30);
        System.out.println(n2);

実行結果
1e

parseInt() 数字の文字列をint型に変換する

String age = "23";
        Integer n = Integer.parseInt(age);
        System.out.println(n);

実行結果
23

valueOf() 数字の文字列をint型に変換する

valueOf()の例
        int ii = 15;
        Integer ii2 = Integer.valueOf(ii);
        System.out.println(ii2);

実行結果
15
valueOf()の例
    String bb = "62";
        Integer bb2 = Integer.valueOf(bb);
        System.out.println(bb2);

実行結果
62
valueOf()の例
    String bb = "62";
        int bb2 = Integer.valueOf(bb);
        System.out.println(bb2);

実行結果
62
valueOf()の例
        int bb2 = Integer.valueOf("50");
        System.out.println(bb2);

実行結果
50

Integer型の変数に入ってる値をint型に変換

Integer型の変数に入ってる値をint型に変換
        int ii = 15;
        Integer ii2 = Integer.valueOf(ii);
        System.out.println(ii2);
        int ii3 = ii2.intValue();//Integer型をint型に変換
        System.out.println(ii3);

実行結果
15

AutoBoxingとAutoUnboxing

        int s1 = 5;
        Integer s2 = s1;
        int s3 = s2;
        System.out.println(s3);

実行結果
5
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4