in computer science, someone asked if arrays could be resized in java.
The instructor answered that arrays had to have a fixed size in all languages.
I had to try very hard not to laugh.
Printable View
in computer science, someone asked if arrays could be resized in java.
The instructor answered that arrays had to have a fixed size in all languages.
I had to try very hard not to laugh.
Did you hit him hard ?
They do.
An array is a block of memory. When you 'resize' an array you create a new block of memory of the appropriate size and copy the old block into the new one and change a few pointers.
I hope you didn't make a fool of yourself ;)
Some arrays will allow you to dynamically resize them without the full copy of the old array (such as the ArrayList in .NET), but the array is still a fixed size at any given time.
Brad!
One assumes, being a list, that it maintains a linked list to each element and simply points at the new memory block when you extend the array.
When I said 'array' I meant elements ordered in memory and accessed through array arithmetic; not a list.
Is the ArrayList of one dimension?
Quote:
Originally posted by yrwyddfa
One assumes, being a list, that it maintains a linked list to each element and simply points at the new memory block when you extend the array.
When I said 'array' I meant elements ordered in memory and accessed through array arithmetic; not a list.
Is the ArrayList of one dimension?
It works (on the outside) just like an array. This means it can be multi-dimensional. You are correct in that on the inside it is a list, which is what allows it to be resized without the need to be copied. This gives it speed over standard arrays, which work as yrwyddfa stated -- a full copy of the original if you resize.
< I took the following out because I thought it was too techie >
ArrayLists are going to be done with generics in .NET 2.0. Generics are like templates in C++ (but aren't the same).
Good idea, really. The boys at M$ have been thinking ;)
. . . and are the same as 'generics' in Ada.Quote:
Generics are similar to -- but not the same as -- templates in C++.
This has an interesting application to my personal identity in Philosophy class.
I would argue that it's the 'same' array because it has the same data (and context for that data) (same mind) but you argue it isn't because it is stored in another area (different body).
:bigyello:
I'd love to se the face of your teacher after you say that.Quote:
Originally posted by alkatran
This has an interesting application to my personal identity in Philosophy class.
I would argue that it's the 'same' array because it has the same data (and context for that data) (same mind) but you argue it isn't because it is stored in another area (different body).
:bigyello:
The syntax is the same, but semantically they are different. It's simply an abstraction of a linked list to make it look like an array.
All of the problems associated with linked lists will still be there, and element access will be slower than standard array element access. The only bit that will be faster is resizing.
http://sicman.ihateclowns.com/clown/fclown.jpg
:afrog:
Well, I was looking for a funny clown to try and remove the serious'ous'ness from this thread, but instead I found a pedi one with a pet monkey. :) Enjoy. :wave:
Your tutor is correct, arrays are static. Runtime arrays are dynamic :bigyello: