• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

transparently expanding array  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, I want to transparently expand my array, but I have a 2D array to work with.
so i made a method like this:
[code]
private MusicCD[] doubleArray(MusicCD original[][]) {

int length = original.length;
MusicCD newArray[] = new MusicCD [length * 2];
System.arraycopy(original, 0, newArray, 0, length);
return newArray;
}
[code]
I guess the problem I am having is how to say anArray[6][] is the one that needs expanding not all.
 
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not use an ArrayList? It works just about the same as an array, as far as maintaining insertion order and such, but it grows dynamically so that you never have to expand your array manually.

If this is definitely not an option there are ways to do it but IMHO it is a bad design to do so.
 
author
Sheriff
Posts: 23569
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


How does this not throw an exception? You are trying to copy elements from one array to another -- but the element types are different.

Henry
 
Brian Legg
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry, I assumed it was a psudo-code method...

ps: How the heck do you spell psudo?
 
Henry Wong
author
Sheriff
Posts: 23569
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

ps: How the heck do you spell psudo?



Yea, it does have a weird spelling...

It's spelled Pseudo.

Henry
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!