This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Integer and Integer object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Integer and Integer object" Watch "Integer and Integer object" New topic
Author

Integer and Integer object

venkatesh badrinathan
Ranch Hand

Joined: Aug 03, 2008
Posts: 77
import java.util.*;
class test
{
public static void main ( String [] args )
{
List < Integer > list = new ArrayList < Integer > ();
for ( int i = 1 ; i<10 ; i++ )
{
list.add(i);
}
list.remove( new Integer(4) ); // 1
list.remove( 1 ); // 2
}
}
ans:Line one removes Integer object 4 and Line 2 removes Integer at index one
my question: actually what do they mean by 'Integer' and 'Integer object'..???


SCJP1.5
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

First of all let me describe you this program if this would clear your confusion-

import java.util.*;
class test
{
public static void main ( String [] args )
{
List < Integer > list = new ArrayList < Integer > ();
for ( int i = 1 ; i<10 ; i++ )
{
list.add(i); //autoboxing
}
list.remove( new Integer(4) ); //removes the Integer object with the value 4
list.remove( 1 ); //removes the Integer Object at the index 1 (i.e. the second value)
}
}

Now everywhere Integer objects are being added and removed. There is no difference between Integer and Integer Object here. don't get confused between int and Integer. Do you get it...If no please describe your question a bit more.... :roll:


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
venkatesh badrinathan
Ranch Hand

Joined: Aug 03, 2008
Posts: 77
Thanks AnkitJi Garg, i have understood what you have told..
 
 
subject: Integer and Integer object