Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array Question

 
mark pays
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a simple way to see if an array is full. I need to write a method that inserts an element at a certain index, and adjusts the other elements accordingly. If the array is full then a new array one element larger will need to be created. If the array is not full then the element can be inserted and the other elements moved accordingly. Does anyone have any ideas?
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The length variable gives you the size of the array. You can loop through to see how many elements actually have something in them. i.e they do not contain the default value associated with the datat type of the array.
I believe a collection, specifically a vector or arrayList will be more appropriate for what you want to do. Check out the API for these classes.

Bosun
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic