Results 1 to 4 of 4
- 06-20-2011, 05:05 AM #1
Member
- Join Date
- Jun 2011
- Posts
- 13
- Rep Power
- 0
What is the diff between int and Integer in terms of array
Hi ,
I'm newbie to Java.
Could anyone pls tell me the diff between int and Integer in terms of Array.
int[] iarray = new int[10];
Integer[] iarray = new Interger[10];
I know that , first one is primitive and second one is class.
The second one requires 80 bytes of memory in order to complete the task, as it stores the reference in the array.
Want to know abt the first one , will it behave same as Integer ?
If I want to store 20 integer value , then which one is best WRT performance?
- 06-20-2011, 05:31 AM #2
What do you mean by difference? Arrays are arrays are arrays regardless of the type stored in them. They do not exhibit any different behaviour. You use them exactly the same. However, since Integer is the wrapper class of the primitive int and they introduced autoboxing you can do this:
Notice how you can insert an int into the Integer array and vice versa. What actually happens behind the scenes is the int value is autoboxed into an Integer object and the Integer object is autounboxed into an int.Java Code:int[] pArray = new int[5]; Integer[] cArray = new Integer[5]; pArray[0] = 10; pArray[1] = new Integer(20); cArray[0] = 30; cArray[1] = new Integer(40); System.out.println(pArray[0]); System.out.println(pArray[1]); System.out.println(cArray[0]); System.out.println(cArray[1]);
- 06-20-2011, 02:50 PM #3
Member
- Join Date
- Jun 2011
- Posts
- 13
- Rep Power
- 0
- 06-21-2011, 01:28 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Similar Threads
-
Integer value in Character Array
By AwesomeGuy in forum New To JavaReplies: 1Last Post: 04-09-2011, 07:41 PM -
arraylist to integer array
By monika in forum Advanced JavaReplies: 3Last Post: 04-26-2010, 09:09 PM -
An Array of different integer values
By lithium002 in forum New To JavaReplies: 7Last Post: 12-04-2009, 05:25 AM -
How to add an integer to a array element and the store that backinto an array.
By Hannguoi in forum New To JavaReplies: 1Last Post: 03-31-2009, 06:40 AM -
Java terms
By Shaolin in forum New To JavaReplies: 2Last Post: 12-27-2007, 05:02 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks