TestUser
package com.example.helloword.demo; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @Data @NoArgsConstructor @AllArgsConstructor public class TestUser { private Integer id; private String mame; private Integer age; }
Demo
package com.example.helloword.demo; import lombok.extern.slf4j.Slf4j; import net.sf.json.JSON; import java.util.ArrayList; import java.util.List; import java.util.Random; @Slf4j public class HellowordDemo { /** * [TestUser(id=0, mame=闫文超0, age=8), * TestUser(id=1, mame=闫文超1, age=16), * TestUser(id=2, mame=闫文超2, age=7), * TestUser(id=3, mame=闫文超3, age=4), * TestUser(id=4, mame=闫文超4, age=4), * TestUser(id=5, mame=闫文超5, age=23), * TestUser(id=6, mame=闫文超6, age=16), * TestUser(id=7, mame=闫文超7, age=21), * TestUser(id=8, mame=闫文超8, age=13), * TestUser(id=9, mame=闫文超9, age=13)] * * ===?[TestUser(id=0, mame=闫文超0, age=8), * TestUser(id=1, mame=闫文超1, age=16), * TestUser(id=2, mame=闫文超2, age=7), * TestUser(id=3, mame=闫文超3, age=4), * TestUser(id=4, mame=闫文超4, age=4), * TestUser(id=5, mame=闫文超5, age=23), * TestUser(id=7, mame=闫文超7, age=21), * TestUser(id=8, mame=闫文超8, age=13), * TestUser(id=9, mame=闫文超9, age=13)] * * @param args */ public static void main(String[] args) { List<TestUser> userList = getUserList(); log.info("userList=====>" + userList); List<TestUser> arrayList = new ArrayList<>(); List<TestUser> arrayList11 = new ArrayList<>(); for (TestUser user : userList) { if (user.getId() % 2 == 0) { if (user.getAge() > 15) { arrayList11.add(user); continue; } } arrayList.add(user); } System.out.println("===?" + arrayList.toString()); System.out.println("===>>>>>-------" + arrayList11.toString()); } private static List<TestUser> getUserList() { List<TestUser> list = new ArrayList<>(); //插入用户 for (int i = 0; i < 20; i++) { TestUser user = new TestUser(); user.setId(i); user.setMame("闫文超" + i); user.setAge(getRanddomAge()); list.add(user); } return list; } private static Integer getRanddomAge() { Random random = new Random(); return random.nextInt(20); } }
continue 就是在条件内循环;循环完出去继续循环其他的;
程序循环控制结构中,表示结束本次循环,若后续还有循环,则继续进行后面的循环