import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.impl.factory.Lists; import org.eclipse.collections.api.block.predicate.Predicate; import org.eclipse.collections.api.block.function.Function; import org.eclipse.collections.api.block.predicate.Predicate2; public class Student { private String name; private int age; public Student(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public int getAge() { return age; } } public class Main { public static void main(String[] args) { MutableList<Student> students = Lists.mutable.of( new Student("Alice", 20), new Student("Bob", 21), new Student("Charlie", 19) ); MutableList<Student> filteredStudents = students.select(student -> student.getAge() >= 20); MutableList<Student> sortedStudents = filteredStudents.sortThisBy(Student::getName); MutableList<String> uppercasedNames = sortedStudents.collect(Student::getName).collect(String::toUpperCase); uppercasedNames.forEach(System.out::println); } } <dependency> <groupId>org.eclipse.collections</groupId> <artifactId>eclipse-collections</artifactId> <version>10.4.0</version> </dependency> groovy dependencies { implementation 'org.eclipse.collections:eclipse-collections:10.4.0' }


上一篇:
下一篇:
切换中文