2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JAVA Integer.intValue() / Integer.valueOf() / AutoBoxing / AutoUnboxing

Last updated at Posted at 2015-11-13

#ラッパークラスへの変換
##■valueOf(Integerに変換したいintの変数)
int を Integerに変換

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

■実行結果
15

■例② int を Integerに変換

		int bb2 = Integer.valueOf("50");
		System.out.println(bb2);

■例② 実行結果
50
#基本データ型への変換
##■intValue(intに変換したいIntegerの変数)
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
15

#ラッパークラス型と基本データ型との間で代入を行う式を記述すると、自動的にvalueOf()や~value()による型変換が行われる
##■AutoBoxingとAutoUnboxing

		int i = 20;
		Integer i2 = i; // intをIntegerに自動変換
		int i3 = i2; // Integerをintに自動変換
		System.out.println(i3);

■実行結果
20

2
3
3

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?