> It wasn't about constructing LinkedList's, but about an array of those.
Fair enough
> You have to specify the size of the array: (e.g.)
> LinkedList[] separate = new LinkedList[42];
> The size can also given through a variable, but once the array
> is created, its size is cast in reinforced concrete :-)
What if you don't know the size of the array when you are writing the code.
Is there a dynamic nature that can be applied to the array class apart from
switching to use ArrayList?
Andreas Leitgeb - 01 Feb 2007 18:49 GMT
>> You have to specify the size of the array: (e.g.)
>> LinkedList[] separate = new LinkedList[42];
>> The size can also given through a variable, but once the array
>> is created, its size is cast in reinforced concrete :-)
>
> What if you don't know the size of the array when you are writing the code.
That is exactly what I meant with "can also given through a variable":
You don't need to know at programming time, but during runtime, when
code flow reaches array-creation.
E.g. you could do:
int randomvar=(int)(1000000*Math.random());
LinkedList[] separate = new LinkedList[randomvar];
and will get an array with some random size.
> Is there a dynamic nature that can be applied to the array class apart from
> switching to use ArrayList?
Once the array (the one with []) is created, it's size is fixed.
For dynamic length structures see the Collection framework.
Farcus Pottysquirt - 02 Feb 2007 02:33 GMT
> That is exactly what I meant with "can also given through a variable":
>
[quoted text clipped - 5 lines]
> LinkedList[] separate = new LinkedList[randomvar];
> and will get an array with some random size.
> Once the array (the one with []) is created, it's size is fixed.
> For dynamic length structures see the Collection framework.
So it doesn't matter how the size is defined, either by a variable or by
a "hard-coded value" the size of an array is fixed when it is defined at
run time.
Makes sense to me.
Daniel Pitts - 02 Feb 2007 17:49 GMT
On Feb 1, 6:33 pm, Farcus Pottysquirt <where_is_my_...@movies.net>
wrote:
> > That is exactly what I meant with "can also given through a variable":
>
[quoted text clipped - 14 lines]
>
> Makes sense to me.
Right, the size of the array object is fixed. But, unlike c++, you
can reassign the reference to a new object.
Object[] myArray = new Object[10];
System.out.println(myArray.length);
myArray = new Object[15];
System.out.println(myArray.length);
output should be:
10
15
Note that I've created two distinctly different arrays, myArray first
points to one, and then later the other.
Christian - 01 Feb 2007 20:38 GMT
Farcus Pottysquirt schrieb:
>> It wasn't about constructing LinkedList's, but about an array of those.
>>
[quoted text clipped - 8 lines]
> Is there a dynamic nature that can be applied to the array class apart from
> switching to use ArrayList?
no arryas size can't be changed dynamically, thats exactly what
collections are for... nothing hinders you to use a collection of a
collection