PDA

View Full Version : get from Array


bert682
10-21-2009, 01:37 PM
Hey guys,
Have a small problem in extracting an int value from an array. Im modifying code for a class exercise so im not 100% sure of all the code. Anyway, here is what I have extracted as the code relating to the array.

private static final int BallArraySize = 10;
private Ball [] ballArray = new Ball [BallArraySize];

I thought that the following would work, it is within a for loop;
int current = Array.getInt(ballArray,i);
but it doesn't.

Any ideas?

Thanks

ckeyrouz
10-21-2009, 02:56 PM
The array ballArray contains elements of type Ball but not of type int.
What you are trying to do is getting ints out of that array which is not possible.

You can do this if you want:
Ball ball = (Ball) Array.get(ballArray,i);

bert682
10-21-2009, 03:48 PM
Managed to solve it by just using a for loop. Thanks for the help.