• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference of int and INTEGER

 
varungoyal goyal
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whats is the diference in
int i="5"

Integer i=new Integer("5");

thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int is a primitive, whereas Integer is a class wrapping this primitive.
Integer provides you useful methods to work with integers.
 
Arjun Palanichamy
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Venu...

int is Java premitive data type. but INTEGER is Wropper Class .is it use for some java collection class dosnt support direct java primitive data type when we will cnvert and use primitive data type to wropper class object type.

you will refer all java util packages.

==============================================

Arjun Palanichamy.
Chennai.
 
Arjun Palanichamy
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Varun...

Here int is Java primitive data type. but INTEGER is Wrapper Class .Is it use for some java collection class dosnt support direct java primitive data type when we will convert and use primitive data type to wrapper class object type.

you will refer the java util packages.

==============================================

Arjun Palanichamy.
Chennai.
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This does not work, since "5" is String and String cannot be implicitly converted to int.

This is OK, is creates int variable i and initializes it with value 5;

This is also OK. It creates Integer variable i, creates an object using Integer(String) constructor with parameter "5" and initializes i with reference to that object.

This is also OK, it just uses different constructor.

This will compile, but throws exception at run-time, since "aaa" cannot be converted to any number.
[ August 18, 2006: Message edited by: Vlado Zajac ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic