| Author |
deleting from array and default list model
|
Greg Gruic
Greenhorn
Joined: Apr 30, 2011
Posts: 8
|
|
When I delete a contact from my list it doesn't give the proper results. it copies the name in the list so there are two or the data stored in the array get copied instead of moved. Any quick ideas
and
please referance Full Code Earlier Post
|
 |
jishnu dasgupta
Ranch Hand
Joined: Mar 11, 2011
Posts: 103
|
|
Hi Greg,
I think if the index specifies the index of the element which actually needs to be deleted, then the statement
is not removing the element at the particular index, but just copying that element in the previous position.So if the element to de deleted is actually present at the given index, then probably you should change the statement to:
and loop to num_entries - 2.
However on a personal note, i beleive that using an arraylist would make the whole task lot simpler and space effective.
|
If debugging is the process of removing bugs, then programming must be the process of putting them in. -- Edsger Dijkstra
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32704
|
|
|
You would have to set the final entry in that array to null. ArrayList does very much the same under the covers, but it uses the System#arraycopy() method.
|
 |
Greg Gruic
Greenhorn
Joined: Apr 30, 2011
Posts: 8
|
|
|
Thanks for the info, unfortunately we were required to do it manually without using array list. (I lost points on the first one we made that was not GUI).
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32704
|
|
You still need to set the last value in the array to null. And what is "not manual" about the method you have been shown?
I didn't say, "use ArrayList", but "ArrayList does that".
|
 |
Greg Gruic
Greenhorn
Joined: Apr 30, 2011
Posts: 8
|
|
Campbell Ritchie wrote:You still need to set the last value in the array to null. And what is "not manual" about the method you have been shown?
I didn't say, "use ArrayList", but "ArrayList does that".
Sorry my reply to not using ArrayList was to jishnu dasgupta. You guys have been very helpful in pointing out some minor things I have overlooked and my final project is getting handed in very shortly.
Thanks,
Greg
|
 |
jishnu dasgupta
Ranch Hand
Joined: Mar 11, 2011
Posts: 103
|
|
you are welcome!!!
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32704
|
|
Good luck with it
|
 |
 |
|
|
subject: deleting from array and default list model
|
|
|