@Before publicvoidsetUp(){ socialSecurities = Lists.newArrayList( new SocialSecurity(1, 12, "小明"), new SocialSecurity(2, 13, "小红"), new SocialSecurity(3, 14, "小王"), new SocialSecurity(4, 15, "小peng") );
idCards = Lists.newArrayList( new IdCard(14, "xiaopeng"), new IdCard(13, "xiaohong"), new IdCard(12, "xiaoming") );
//目标: 从socialSecurities中筛选出idCards中存在的卡片 }
遍历
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
@Test publicvoidtestFilterForEach(){ List<SocialSecurity> result = new ArrayList<>(); int count = 0; for (SocialSecurity socialSecurity : socialSecurities) { for (IdCard idCard : idCards) { count++; if (socialSecurity.getIdCard().equals(idCard.getId())){ result.add(socialSecurity); } } }
@Test publicvoidtestCondition(){ int maxN = 0; for (int m = 2; m < 100; m++) { for (int n = 3; n < 100; n++) { if ((2*m+n)>m*n){ System.out.println("m="+m +",n="+n); if (n>maxN){ maxN = n; } } } }