Click to See Complete Forum and Search --> : Return size of Arrays? Arrays.size(); ?


n_codrington
09-23-2008, 01:34 PM
Hey guys. I have the code:

int[] nums = {2, 7, 1, 8, 2, 8};
Arrays.asList(nums);
System.out.print(Arrays.size(nums));


...it compiles everything before System.out...etc.

And I get the exception: "cannot find symbol - method size(int[])"

What's wrong?

FourCourtJester
09-23-2008, 02:32 PM
The problem is you're calling a method (size[int[])) that doesn't exist on that object (Arrays).

Try mimicking the following code:

List stooges = Arrays.asList("Larry", "Moe", "Curly");
System.out.print(stooges.size());

chazzy
09-23-2008, 08:19 PM
or you could do


System.out.print(nums.length);

n_codrington
09-23-2008, 09:34 PM
Thanks, length works!