ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

A java question, please help if you have the time

(1/2) > >>

zacorbul:
Hello,
I have an int[] and I would like to wrapp it in an Integer[].
I know that
Integer convertInt = int aNumber;   
But I am not sure how I would go about it for an array.
I tried using a for loop such as:
for(int i=0; i<aNumber.length; i++)
 convertInt = aNumber

but is no use as I get an error (array dimension missing)while declaring
Integer[] convertInt = new Integer[];

If anybody could help me get back on track it would be great.
 Thank you

jgpaiva:
You get that error because you need to specify a size to the array you create, try doing

--- ---Integer[] convertInt = new Integer[intArray.size()](0);

I'm not absolutelly sure if that's the syntax and currently i don't have eclipse installed to confirm.

OGroeger:
nearly there ;-)

--- ---  int[] ints = new int[]{1,2,3,4,5};
  Integer[] intObjects = new Integer[ ints.length ];
  for( int i = 0; i < ints.length; ++i )
  {
  intObjects[ i ] = new Integer( ints[ i ] );
  }

jgpaiva:
Right, OGroeger!

(and i'm the one who loves java  :huh:)

zacorbul:
Thank you very much for answering all and especially OGroeger, it was spot on, it worked like a charm(actually better)  :Thmbsup:

Now I can finally finish my method. ;D
Thank you guys, I owe you a pint of lager :)

Cheers

Navigation

[0] Message Index

[#] Next page

Go to full version