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 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; }

I do not use an iterator can . [...] I need to use each loop

Here's a way:

  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; }   

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 iList.remove (item) line.

But better methods should be divided:

  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

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -