我是靠谱客的博主 糟糕手套,这篇文章主要介绍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中删除List中的某些数据的方法的全部内容,更多相关Java中删除List中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(122)

评论列表共有 0 条评论

立即
投稿
返回
顶部