Lambda = λ
LambdaJ 的主要目的是简化对集合的操作。下面的代码展示了 LambdaJ 是如何简化的:
本文所用代码示例引用自:[url=http://java.dzone.com/articles/manipulating-collections]http://java.dzone.com/articles/manipulating-collections[/url]
LambdaJ: [url=http://code.google.com/p/lambdaj/]http://code.google.com/p/lambdaj/[/url]
=============补充==============
提供便利功能的同时,多少是要付出一些代价的。我并没有测试 LambdaJ 的性能,但是在对性能敏感的场景中使用时还是要谨慎的。
LambdaJ 的主要目的是简化对集合的操作。下面的代码展示了 LambdaJ 是如何简化的:
List<Person> personInFamily = asList(new Person("Domenico"), new Person("Mario"), new Person("Irma"));
forEach(personInFamily).setLastName("Fusco");
List<Person> sortedByAgePersons = sort(persons, on(Person.class).getAge());
// Plain Java code
List<Person> sortedByAgePersons = new ArrayList<Person>(persons);
Collections.sort(sortedByAgePersons, new Comparator<Person>() {
public int compare(Person p1, Person p2) {
return Integer.valueOf(p1.getAge()).compareTo(p2.getAge());
}
});
本文所用代码示例引用自:[url=http://java.dzone.com/articles/manipulating-collections]http://java.dzone.com/articles/manipulating-collections[/url]
LambdaJ: [url=http://code.google.com/p/lambdaj/]http://code.google.com/p/lambdaj/[/url]
=============补充==============
提供便利功能的同时,多少是要付出一些代价的。我并没有测试 LambdaJ 的性能,但是在对性能敏感的场景中使用时还是要谨慎的。