package books;
import java.util.Collection;
import java.util.HashSet;
import java.util.function.Predicate;
public class PredictTest2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Collection books=new HashSet();
books.add(new String("轻量级Java EE企业应用实战"));
books.add(new String("疯狂Java讲义"));
books.add (new String("疯狂IOS讲义"));
books.add(new String("疯狂Android讲义"));
books.add(new String("疯狂AJAX讲义"));
System.out.println("疯狂的个数 "+count(books,e->((String) e).contains("疯狂")));
System.out.println("java的个数 "+count(books,e->((String) e).contains("Java")));
System.out.println("字符串长度>10的个数 "+count(books,e->((String) e).length()>10));
}
public static int count(Collection book,Predicate p) {
int total=0;
for(Object obj:book)
{
//判断obj是否满足指定的条件,使用predicate可以只写一个方法
if(p.test(obj))
{
total++;
}
}
return total;
}
}