MapLong ListLiveUserRecord classifiedMap = liveUserRecordListstream collectCollectorsgroupingByLiveUserRecordgetUserId;循环拿到键和值
You can iterate over the keys and values of the classifiedMap using a forEach loop or by using the entrySet() method. Here's an example:
classifiedMap.forEach((userId, userRecordList) -> {
// Perform operations on each key-value pair
System.out.println("User ID: " + userId);
System.out.println("User Records: " + userRecordList);
});
Alternatively, you can use the entrySet() method to iterate over the map entries:
for (Map.Entry<Long, List<LiveUserRecord>> entry : classifiedMap.entrySet()) {
Long userId = entry.getKey();
List<LiveUserRecord> userRecordList = entry.getValue();
// Perform operations on each key-value pair
System.out.println("User ID: " + userId);
System.out.println("User Records: " + userRecordList);
}
In both cases, you can access the key (User ID) using entry.getKey() and the value (User Record List) using entry.getValue().
原文地址: https://www.cveoy.top/t/topic/i5su 著作权归作者所有。请勿转载和采集!