Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

deleting from array and default list model  RSS feed

 
Greg Gruic
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 103
Eclipse IDE Java Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 55687
162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 55687
162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 103
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are welcome!!!
 
Campbell Ritchie
Marshal
Posts: 55687
162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good luck with it
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!