• 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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
Posts: 23811
140
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
Posts: 23811
140
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!