-1

1>Integer ie = Integer.valueOf("45");//give output 45

2>int ie = Integer.valueof("45");//give same output as 45

// can you tell me difference between 1 and second statement

3>Integer i3 = Integer.valueOf("70");//give output as 70

4>int i3 = Integer.valueOf("70");// also give same output

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ajay Pal
  • 19
  • 1

2 Answers2

1

Its called unBoxing in java which was introduced in JAVA 5 Integer is wrapper class which provides Integer object to un-boxed into int primitive data type. Integer has static methods like

static Integer valueOf(int i)
static Integer valueOf(String s)
static Integer valueOf(String s, int radix)

Similar wrapper classes for other primitive data types

byte has Byte
short has Short
int has Integer
long has Long
boolean has Boolean
char has Character
float has Float
double has Double 
Bhargav Modi
  • 2,605
  • 3
  • 29
  • 49
0

The first query gives you an Objectof type Integer.

The second query gives you a primitive type int. That will be the same as Integer.valueof("45").intValue();

Jens
  • 67,715
  • 15
  • 98
  • 113