0

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;
}
2
Contributors
3
Replies
5
Views
9 Years
Discussion Span
Last Post by masijade
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).

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.