安卓篱笆

  • 400-800-1234
  • 为您定制专业的垂直门户
搜索
猜你喜欢
查看: 2942|回复: 0
打印 上一主题 下一主题
收起左侧

聚合操作例子(oracle甲骨文官网示例)

[复制链接]

308

主题

307

帖子

1097

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1097
跳转到指定楼层
楼主
发表于 2018-1-4 09:34:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,,享用更多功能,让你轻松玩转本站。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
import java.lang.Iterable;
import java.lang.Number;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

public class BulkDataOperationsExamples {
   
    public static void main(String... args) {
        
        // Create sample data

        List<Person> roster = Person.createRoster();
        
        // 1. Print names of members, for-each loop
        
        System.out.println("Members of the collection (for-each loop):");
        for (Person p : roster) {
            System.out.println(p.getName());
        }
        
        // 2. Print names of members, forEach operation
        
        System.out.println("Members of the collection (bulk data operations):");
        roster
            .stream()
            .forEach(e -> System.out.println(e.getName()));
            
        // 3. Print names of male members, forEach operation

        System.out.println(
            "Male members of the collection (bulk data operations):");
        roster
            .stream()
            .filter(e -> e.getGender() == Person.Sex.MALE)
            .forEach(e -> System.out.println(e.getName()));
            
        // 4. Print names of male members, for-each loop

        System.out.println("Male members of the collection (for-each loop):");
        for (Person p : roster) {
            if (p.getGender() == Person.Sex.MALE) {
                System.out.println(p.getName());
            }
        }
         
        // 5. Get average age of male members of the collection:
        
        double average = roster
            .stream()
            .filter(p -> p.getGender() == Person.Sex.MALE)
            .mapToInt(Person::getAge)
            .average()
            .getAsDouble();
            
        System.out.println(
            "Average age of male members (bulk data operations): " +
            average);
    }
}
回复

使用道具 举报

*滑动验证:
使用 高级模式(可批量传图、插入视频等)
您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /3 下一条

快速回复 返回顶部 返回列表