• Post Reply Bookmark Topic Watch Topic
  • New Topic

Find out element deleted  RSS feed

 
Suresh Narayana
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i have an array of 100 element, we delete 1 element, now how will i know which element i have deleted
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You access an array by its index, so you always know.
 
Tyson Lindner
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suresh Narayana wrote:we delete 1 element, now how will i know which element i have deleted


Short-term memory?

I think you might mean if you have an "array" like an ArrayList, and something is randomly deleted, how do you determine what it was. If you knew the contents of the array before deletion, you cycle through the new array and figure out what's missing by process of elimination. Otherwise there's really no way to tell. Your new array doesn't save information on previous deletions or anything.
 
Robert D. Smith
Ranch Hand
Posts: 221
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically, store the index number as you delete the element (set it to 0 or "" or what have you). The only other option that i can think of would be to loop through the array and check each element.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need that information? There may be an easier way to solve your problem.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!