集合对象都有createId和updateId, 他们都是字符串类型,如何获取集合中所有的createId和updateId,如何使用java或者stream来实现
时间: 2024-04-30 21:17:18 浏览: 19
您可以使用Java中的Stream来获取集合中所有的createId和updateId。
例如,如果您有一个包含对象的集合,每个对象都有createId和updateId属性,您可以按以下方式获取所有的createId和updateId。
```
List<YourObject> yourCollection = ... // 假设您有一个包含YourObject类型的集合
// 使用Stream获取所有的createId
List<String> createIds = yourCollection.stream()
.map(YourObject::getCreateId)
.collect(Collectors.toList());
// 使用Stream获取所有的updateId
List<String> updateIds = yourCollection.stream()
.map(YourObject::getUpdateId)
.collect(Collectors.toList());
```
这段代码使用Stream对集合进行了操作,通过调用`stream()`方法从集合中获取一个Stream对象,然后使用`map()`方法将集合中每个对象的createId或updateId属性映射到一个新的Stream中,最后使用`collect()`方法将新的Stream转换为一个List。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)