经过试验,删除List中某些数据的最好的方法是使用iterator,如果有什么不对的地方,请指正批评;记录代码:
/** * 去除未发布状态的课件,并删除其在数据库的存储 * @param listLessons * @return */ public static List<LessonModel> removeUnpublishedLessons(KorenpineApplication application, List<LessonModel> listLessons){ if(null == listLessons || listLessons.size() == 0){ return null; } LogUtils.e(TAG + "课件--removeUnpublishedLessons剔除开始--size-->" + listLessons.size()); Iterator<LessonModel> it = listLessons.iterator(); LessonModel model = null; while (it.hasNext()) { model = it.next(); if (model.getStatus() != 1) { /*课件未发布,剔除*/ LessonModelDB.newInstance(application).deleteByCourseIdAndLessonId(model.getCourseid(), Integer.parseInt(model.getId())); LogUtils.d(TAG + "课件--removeUnpublishedLessons剔除-->" + model.getId()); it.remove(); } } LogUtils.e(TAG + "课件--removeUnpublishedLessons剔除结束--size-->" + listLessons.size()); return listLessons; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/super_spy/article/details/47747199