慕田峪9158850
可能不太简洁,但是可以自己写:importjava.util.Arrays;importjava.util.Iterator;importjava.util.List;publicfinalclassListUtils{publicstaticTcollectFirst(finalIterablelist,finalPredicatepredicate){for(Telement:list){if(predicate.apply(element)){returnelement;}}returnnull;}publicstaticIterablemap(finalIterablelist,finalF1func){returnnewIterable(){@OverridepublicIteratoriterator(){returnnewIterator(){privateIteratori=list.iterator();@OverridepublicbooleanhasNext(){returni.hasNext();}@OverridepublicBnext(){returnfunc.apply(i.next());}@Overridepublicvoidremove(){i.next();}};}};}publicstaticvoidmain(String[]args){finalListintegers=Arrays.asList(1,2,3,4,5,6);finalIntegerresult=collectFirst(integers,newPredicate(){@Overridepublicbooleanapply(Integere){returne.compareTo(3)>0;}});System.out.println(String.format("Thefirstintegerlargerthan3is%d",result));finalIterableresults=map(integers,newF1(){@OverridepublicIntegerapply(Integerinteger){returninteger*integer;}});System.out.println("Thesquaresofthemare:");for(Integeri:results){System.out.print(i+"");}}publicinterfacePredicate{booleanapply(finalTe);}publicinterfaceF1{Bapply(finalAa);}}