aspose file tools*
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
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: 9313
    
  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