Welcome Guest.   Make a donation to an author on the site April 24, 2014, 04:05:35 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
View the new Member Awards and Badges page.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: A java question, please help if you have the time  (Read 2578 times)
zacorbul
Participant
*
Posts: 2

View Profile Give some DonationCredits to this forum member
« on: September 11, 2007, 08:11:34 AM »

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
Logged
jgpaiva
Global Moderator
*****
Posts: 4,710



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #1 on: September 11, 2007, 10:47:43 AM »

You get that error because you need to specify a size to the array you create, try doing
[copy or print]
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.
Logged

OGroeger
Charter Member
***
Posts: 76


View Profile Give some DonationCredits to this forum member
« Reply #2 on: September 11, 2007, 11:48:32 AM »

nearly there ;-)
[copy or print]
  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 ] );
  }
Logged
jgpaiva
Global Moderator
*****
Posts: 4,710



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #3 on: September 11, 2007, 12:12:51 PM »

Right, OGroeger!

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

zacorbul
Participant
*
Posts: 2

View Profile Give some DonationCredits to this forum member
« Reply #4 on: September 11, 2007, 07:33:50 PM »

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. Grin
Thank you guys, I owe you a pint of lager smiley

Cheers
Logged
OGroeger
Charter Member
***
Posts: 76


View Profile Give some DonationCredits to this forum member
« Reply #5 on: September 12, 2007, 03:09:18 AM »

Btw, there a lot of useful classes which can be very helpful. What i use very much is the Apache commons project, in particular the lang project (JavaDoc) which contains "Utils" packages, e.g. ArrayUtils which has a toObject() method that converts an int[] to Integer[].
 
The package that i use on every Project (when possible) is StringUtils. I coundn't live without StringUtils.defaultString() and StringUtils.isBlank().
Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.031s | Server load: 0.16 ]