File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes deleting from array and default list model Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "deleting from array and default list model" Watch "deleting from array and default list model" New topic
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
    
    4
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
    
    4
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
    
    4
Good luck with it
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: deleting from array and default list model
 
Similar Threads
i don't know what i'm doing
Using text fields to update a selection list
array out of bounds and adding double contact
Address Book Java Issues
values are not populated in browser