public static void main(String[] args) {
List<TAdslot> userList = new ArrayList<>();
TAdslot adslot1 = new TAdslot();
adslot1.setName("One");
TAdslot adslot2 = new TAdslot();
adslot2.setName("Zero");
TAdslot adslot3 = new TAdslot();
adslot3.setName("Two");
TAdslot adslot4 = new TAdslot();
adslot4.setName("Four");
userList.add(adslot1);
userList.add(adslot2);
userList.add(adslot3);
userList.add(adslot4);
List<String> stringList = userList.stream().map(TAdslot::getName).collect(Collectors.toList());
System.out.println(stringList);
}
输出结果:
[One, Zero, Two, Four]
list stream:将对象List中的某个字段放到新的List中
最新推荐文章于 2024-01-21 03:23:15 发布