Lambda表达式使用整理总结
发布日期:2021-05-14 06:37:51 浏览次数:11 分类:精选文章

本文共 2546 字,大约阅读时间需要 8 分钟。

Lambda ������������������������������������������

Lambda ������������������ lambda expression ��� Java 8 ������������������������������������������������������������������ "><" ��� "���" ������������������������������������������������������������������������������������������������������������������������������

Lambda ������������������������

Lambda ���������������������������������������������

  • ���������������������������������������������������������������������������
  • Lambda ������������������������������������������������������������������������������
  • Lambda ���������������������������������

    • ��� Lambda ���������������������������
      (parameters) ��� expression
    • ��� Lambda ���������������������������
      (parameters) ��� {     statement;     ...}

    Lambda ������������������������������

  • ���������������������������������

    ������ Lambda ������������������������ forEach ���������������

    String[] names = {"���", "���", "���"};List
    nameList = Arrays.asList(names);nameList.forEach(name ��� { System.out.print(name + "; ");});
  • Stream ���������������������������������

    List
    users = users.stream() .filter(user ��� user.getName().equals("���������")) .collect(Collectors.toList());
    List
    nums = Arrays.asList(100, 200, 300, 400, 500);nums.stream() .map(num ��� num + 12) .forEach(System.out::println);
  • ���������������������������������

    Arrays.sort(names, String::compareTo);
  • ���������������������������������������

    String str = userList.stream()    .filter(user ��� "���".equals(user.getName()))    .collect(Collectors.joining(","));
    Set
    names = userList.stream() .filter(user ��� "���".equals(user.getName())) .collect(Collectors.toSet());
    TreeSet
    names = userList.stream() .filter(user ��� "���".equals(user.getName())) .collect(Collectors.toCollection(TreeSet::new));
  • ������������������������������

    Runnable race = () ��� System.out.println("Hello world!");new Thread(race).start();
  • Lambda ������������������������

  • ������������������������������������������������������������������
  • ���������������������������������������������������������������������������������������������
  • ���������������������������������������������������������������������
  • Lambda ������������������������

  • ��������������������������������� Lambda ��������������������������������������������������������������� final������������������������������������������������������������������
  • ���������������������Lambda ���������������������������������������������������������������������
  • 上一篇:spring data jpa复杂多条件查询
    下一篇:使用AOP给springboot项目添加日志

    发表评论

    最新留言

    关注你微信了!
    [***.104.42.241]2025年04月06日 19时29分37秒