java for循环 去除为空项
文章目录
List<T> photos = new ArrayList<>();
int size = photos.size();
for(int i = size - 1; i >= 0; i--){
if(photos.get(i) == null){
photos.remove(i);
}
}
移除list中某空项时,for循环从list最后一项开始遍历,去除。不然可能出现脚标异常
List<T> photos = new ArrayList<>();
int size = photos.size();
for(int i = size - 1; i >= 0; i--){
if(photos.get(i) == null){
photos.remove(i);
}
}
移除list中某空项时,for循环从list最后一项开始遍历,去除。不然可能出现脚标异常
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册⭐️ Admin快速开发: https://show.cool-admin.com/
赞 0⭐️ 官方文档: https://cool-js.com
赞 0⭐️ chatgpt在线体验: https://cool-js.com/ai/chat-vip/index.html?r=helloworld
赞 0