6
2

More than 3 years have passed since last update.

【Java】parseIntとvalueOfの違い

Posted at

プログラミング勉強日記

2020年11月17日
コードを書いていて、parseIntvalueOfの違いがわからなかったので備忘録として残しておく。

違い

 コードを実行したときに結果が同じになる。調べてみると戻り値が違うと出てきた。具体的には、parseIntがint型やchar型などのプリミティブ型でvalueOfはIntegerクラスを返す。

public class Main {
    public static void main(String[] args) throws Exception {
        int hoge = Integer.valueOf("12345");
        System.out.println(hoge);

        int fuga = Integer.parseInt("12345");
        System.out.println(fuga);
    }
}
実行結果
12345
12345

参考文献

parseIntとvalueOfの違い
parseIntとvalueOfの違いって何!?

6
2
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
6
2