I can't figure how to get this going, for every object I create I want to add that to the existing array. I read about arraycopy but I don't know how to increase the existing size of the array and always end up with array out of index error...
iamthwee is right, you should be using ArrayList. You cannot increase the size of an existing array. You have to create a new array that is one larger than the current array, then you can use System.arraycopy to copy the existing elements from the old to the new array, than add the new element.
Doh! Ok, then, I'll just increase the size of the array. I was doing somethig similar to below, everything is done but I thought it would be neat idea to increase the array dynamically.
prompt user for input
checkinput()
if no dupe add to array
else error msg
Doh! Ok, then, I'll just increase the size of the array. I was doing somethig similar to below, everything is done but I thought it would be neat idea to increase the array dynamically.
prompt user for input
checkinput()
if no dupe add to array
else error msg
Doh! Ok, then, I'll just increase the size of the array. I was doing somethig similar to below, everything is done but I thought it would be neat idea to increase the array dynamically.
prompt user for input
checkinput()
if no dupe add to array
else error msg
you need to know that the array that you use in java is not flexible to increase the size of the array by itself, the array is a STATIC data structure.
this array will remain in your scope of length 10, unless you make a new array that is nor related to that one and of bigger size and then put the elements of the first array in the second array and then make the first array point to the second array.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.