This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

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: 23816
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: 23816
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
 
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!