Java中删除List中的某些数据的方法

经过试验,删除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;
	}


你可能感兴趣的:(java,android,list,集合)