This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Array Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Array Question" Watch "Array Question" New topic
Author

Array Question

mark pays
Greenhorn

Joined: Nov 21, 2000
Posts: 6
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

Joined: Nov 06, 2000
Posts: 1510
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

Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Array Question
 
Similar Threads
Searching, copying, and concatenating arrays
Array simple question
pass by reference- Swapping problem
array copy question
Help with adding elements to vector