Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need to find and remove all instances of an object from an array without using ArrayLists or any of their functions. I need to
I need to find and remove all instances of an object from an array without using ArrayLists or any of their functions. I need to create a loop that iterates through the array and finds the matching objects. It is supposed to remove all matching objects and return the number of matching objects removed. This is the code I have so far please make sure if you answer this that it is NOT using ArrayList functions I have created my own basic array and am programming the method removeAll() manually.
/** * Removes all instances of this object from the list. * * @param obj the object to match for removal * @return the number of objects removed */ int removeAll(GenClass obj) { int removedObj = 0; //it should be array.length not count for the loop for (int i = 0; i < array.length; i++) { if (array[i] == obj) { delete(i); removedObj++; } } return removedObj; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started