public class Customer {

      private int id;

      private String name;

//其他省略 }

//建立测试数据

List<Customer> customers = new ArrayList<>();

     customers.add(new Customer(1, "Jack"));

     customers.add(new Customer(2, "James"));

     customers.add(new Customer(3, "Kelly"));

//实现查找,找到则返回匹配的对象,找不到则返回null

Customer james = customers.stream() .filter(customer -> "James".equals(customer.getName())) .findAny() .orElse(null);

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2021-08-11
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案