This content has been marked as final. Show 5 replies
Arrays don't allow this, but there are other structures that do. Collections such as ArrayList, LinkedList, and Vector do this.
This does not work, even though it does in other languages such as PHP.Not every language is the subset of some other language.
Lots of languages allow this, APL for instance is based on arrays or any dimension and allows catenation on any of those dimensions. You can also take part of a mulitdimensional array, transpose or reverse it and glue two of them together. If they are numeric you can add them together, take their matrix inverse and do linear algebra on them.
All this comes a a very high cost in performance. Every time you change the size of an array the system must make a copy. If arrays have fixed size these copies aren't needed. If you really need an Array Programming Language, get one, but don't ask Java to do that.
Supposedly Sun is working on a language, code named Fortress, that will provide many of these features, if it ever sees the light of day.
Hashmir wrote:A simple shortcut is to declare a "cursor" and use that to index. This makes all of your declarations look the same, at least, without the need to hardcode indices:
int newArr = new int; newArr = 4; newArr = 6;
It results in a minuscule performance hit for the sake of cleanliness.
int newArr = new int; int i = 0; //cursor newArr[i++] = 4; newArr[i++] = 6; newArr[i++] = 7; //etc.
Hashmir wrote:Also, this is an impossible state for a primitive array. Each element in a primitive array is always instantiated to 0, so what you'd really have is
[ ][ ][ ]