Arrays...java

Started by
11 comments, last by DevFred 17 years ago
Hey guys I want to perform a deletion operation on arrays but I have no clues about how should I proceed with it .If an item in the array matches with the parameter passed how am I supposed to delete it?....can anybody help me out with the algorithm for this deletion job.It's a java project. Thanks, -Nidhi
Advertisement
There are 2 easy ways to delete an element from an array. One is to mark the element in some way so you know it has been deleted. Another is to move every element after the deletee back to occupy its space.

For the first method, remember that its fairly easy to mark something as deleted by setting it to null, provided of course that the rest of your program doesn't assume that every element in the array has to point to something valid.
hey rip-off


ok if I use the second method..Do I have to copy the value of all the old elements ,which were before the element that I want to delete, to a new array and then move all the elements which were after the element to be deleted one step ahead.And the new array should be one less than the original array


I'm confused
hey rip-off


ok if I use the second method..Do I have to copy the value of all the old elements ,which were before the element that I want to delete, to a new array and then move all the elements which were after the element to be deleted one step ahead.And the new array should be one less than the original array


I'm confused
Use a Vector.
Seriously I don't know anything about vectore coz I haven't used it.I need a simple approach to this operation..Please help me out!
Quote:Original post by Nidhi
Seriously I don't know anything about vectore coz I haven't used it.I need a simple approach to this operation..Please help me out!


Are you doing this for use in a program, for learning about arrays or as homework?
Well not as a homework..Actually we(me and some members of java users group on campus)are stuck on dis thing.We are working on a project that requires the use of deletion operation on arrays!
Quote:Original post by Nidhi
Well not as a homework..Actually we(me and some members of java users group on campus)are stuck on dis thing.We are working on a project that requires the use of deletion operation on arrays!


If the project is not about learning how to use arrays, then I would recommend using a class like ArrayList or Vector to hold your data, as these allow you to easily remove items.

If demonstrating array knowledge is part of the project then we cannot help you directly, however if you post some code we may be able to hint you to where you are going wrong.
ok

This topic is closed to new replies.

Advertisement