RxJava alternative of group by in sql
问题 I have a list of Student : Observable<Student> source = Observable.fromIterable(getStudentList()); I would like to group them by postal code, along with how many times they appear, but the problem is that I use java 7 how to do this? 回答1: Use groupBy , flatMap and count on the groups themselves: source.groupBy(s -> s.postalCode) .flatMapSingle(g -> g.count() .map(v -> g.getKey() + ": " + v)) ; Without lambdas it looks more ugly though: source.groupBy(new Function<Student, String>() {