|
-
Nov 14th, 2005, 09:45 AM
#1
Thread Starter
Fanatic Member
The size of an array
I have created an integer array, i want to store the size of the array in a variable (for an insertion sort). But i get an error when i do the following code.
Code:
int[] myArray;
int lastPos = myArray.length();
The error is "cannot perform length() on an integer array" (or something similar to that, i'm not at my computer now so i cant see the error).
What is the problem?
Last edited by x-ice; Feb 25th, 2007 at 07:24 PM.
-
Nov 14th, 2005, 10:31 AM
#2
Re: The size of an array
The array hasn't been initialised.
int[] a = new int[3];
-
Nov 14th, 2005, 11:44 AM
#3
Thread Starter
Fanatic Member
Re: The size of an array
 Originally Posted by DeadEyes
The array hasn't been initialised.
int[] a = new int[3];
How can i initialise an array that i dont know the size of, also can i change the size at a later time? I dont want to use an ArrayList (these are dynamic, size isn't a problem with these).
-
Nov 14th, 2005, 01:32 PM
#4
Re: The size of an array
You can add to the array any time you want.
But you can't assign the length to a variable until it has a value
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Nov 14th, 2005, 04:55 PM
#5
Thread Starter
Fanatic Member
Re: The size of an array
 Originally Posted by ComputerJy
You can add to the array any time you want.
But you can't assign the length to a variable until it has a value
So if for example i assign 10 spaces for the array when i initialise it, can i then add more spaces once there is data in the array without losing the data?
-
Nov 14th, 2005, 04:59 PM
#6
Re: The size of an array
 Originally Posted by x-ice
So if for example i assign 10 spaces for the array when i initialise it, can i then add more spaces once there is data in the array without losing the data?
Normally for a dynamically sized list, you would use one of the many Collection classes, like ArrayList for instance.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 14th, 2005, 05:10 PM
#7
Re: The size of an array
 Originally Posted by x-ice
So if for example i assign 10 spaces for the array when i initialise it, can i then add more spaces once there is data in the array without losing the data?
You can use arrays concatenation any time, without losing data
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|