当前位置: 代码迷 >> 综合 >> JDK8泛型特性之List<Object>指定参数转换为List<String>
  详细解决方案

JDK8泛型特性之List<Object>指定参数转换为List<String>

热度:30   发布时间:2023-10-16 10:32:12.0

需求

将一个对象集合的id提取出来生成一个新的集合

解决方案

List<User> ev = new ArrayList<>();
List<String> ids = ev.stream().map(User::getId).collect(Collectors.toList())

将红色部分改为自己的对象和参数即可

  相关解决方案