java - How to return an object that was deleted? -
I have a method that is considered to remove a list list (iList) in a list list (i) , When the inventory item has been entered as part of the description. This method must be returned to the deleted item, and I am unsure how to do it. Here is my code so far I do not use an iterator can . [...] I need to use each loop Here's a way: Note that this removes a maximum of one object from the list. If there are many matches, then only the first match will be removed. If I only want to find the object instead of deleting the object, [...] Then you just leave the But better methods should be divided: Delete public inventory item- inventoryitim (string descriptioni) {int index = -1; Boolean result = false; (Inventory I: iList) {if (i.getDescription (). ToLowerCase (). Start (descriptionIn.toLowerCase ())) {index = (iList.indexOf (i)); Result = true; } If (index> = 0) {iList.remove (index); }} Return tap; }
public inventory Itam DeletionInventory (In String Description) (Inventory Item Item: iList) if (item.getDescription () .toLowerCase () with .starts (descriptionIn.toLowerCase ())) {iList.remove (item); Object back; }} Return tap; }
iList.remove (item) line.
Public Inventory Item Search Inventory (in String Description) Inventory (for Inventory Items: iList) if ( item.getDescription () .toLowerCase () .starts (description .overcases ())) {return items; }} Return tap; } Public Inventory Item RemovalInitium (String Description) {Inventory Item Item = Search Inventory Item (Details); If (item! = Null) iList.remove (item); Object back; }
Comments
Post a Comment