遍历 List 集合可以使用 for 循环或者 foreach 循环。

使用 for 循环遍历集合:

List<NoticeLog> all = noticeLogService.getAll();
for (int i = 0; i < all.size(); i++) {
    NoticeLog noticeLog = all.get(i);
    // 执行相应的操作
}

使用 foreach 循环遍历集合:

List<NoticeLog> all = noticeLogService.getAll();
for (NoticeLog noticeLog : all) {
    // 执行相应的操作
}
Java List 集合遍历:for 循环和 foreach 循环

原文地址: https://www.cveoy.top/t/topic/jZzi 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录