After experimentation, the best way to remove some data from the list is to use iterator, and if anything is wrong, criticize it; Record code:
/** * Remove the non-published courseware and delete its storage in the database * @param listlessons * @return */public static list<lessonmodel> removeunpublishedless ONS (korenpineapplication application, list<lessonmodel> listlessons) {if (null = = Listlessons | | listLessons.size () = = 0) {return null;} LOGUTILS.E (TAG + "courseware--removeunpublishedlessons culling start--size-->" + listlessons.size ());iterator<lessonmodel> it = Listlessons.iterator (); Lessonmodel model = NULL; while (It.hasnext ()) { model = It.next (); if (Model.getstatus ()! = 1) {/ * Courseware not published, exclude */ lessonmodeldb.newinstance (application). Deletebycourseidandlessonid (Model.getcourseid (), Integer.parseint (Model.getid ())); LOGUTILS.D (TAG + "courseware--removeunpublishedlessons excluded--" + Model.getid ()); It.remove (); } } LOGUTILS.E (TAG + "courseware--removeunpublishedlessons culling end--size-->" + listlessons.size ()); return listlessons;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Ways to remove some data from a list in Java