954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Deleting record

Hi. Can anyone help me on my code? I wanted to delete a data inside a array, so what I did was to move the the array into another array without the one that is to be deleted. It is working if the user only wants to delete a single record. How can I improve my code without using vectors?

OR is there a better way of deleting data inside an array?

case 3:
{
System.out.println("Delete a array entry: ");
int d = Integer.parseInt(input.readLine());
while (i < a.length && j < b.length) {
if (d == a[i]) {
i++;
}
else {
b[j] = a[i];
i++;
j++;
}
}
break;
}
case 4:
{
System.out.println("View All");
for(i=1;i<a.length;i++)
{
if(a[i] == 0){
break;
}
else
System.out.println(a[i]);
}
break;
}
pickachu
Newbie Poster
9 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

To tell you the truth, you would be much better off using an ArrayList, otherwise, place this code into a method that accepts an array and an element as arguments, and returns an array, then call this method for each element to be removed (is one fairly inefficent way). Or, place all elements to be removed in another array, then loop over the original array, and inside that, loop over the smaller array and comparing them (another ineffecient way).

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

Can you refer me to any ArrayList tutorial or some thing like that?

pickachu
Newbie Poster
9 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

http://java.sun.com/

Go to documentation, you'll find the Collections tutorials (as well as all the others) somewhere under there.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You