Java - 如何根据其元素的属性分隔列表 [英] Java - How to separate a list based on a property of it's elements
问题描述
根据需要,根据其元素的给定属性分离列表的最佳方法是什么?将在原始列表中传递的对象的数量最多为< 10,000, 1,000。
所有的帮助非常感谢!
像您可能想使用 Multimaps.index
来自 Guava 。这将为您建立一个多地图,每个键都有一个元素集合。
将 keyFunction
index
将是一个函数
,它只是从单个元素中检索属性。
I have a list of objects which I want to perform an operation on. However I firstly need to divide the list into separate lists such that all items with the same parentID are in the same list, and then the operation is performed on each list separately (the reason being that the operation takes the parentID of the objects as a parameter).
What is the best way to separate a list based on a given property of it's elements, as required here? The highest number of objects that will be passed in the original list is < 10,000 and normally will be < 1,000.
All help is much appreciated!
It sounds like you might want to use Multimaps.index
from Guava. That will build you a multi-map, where each key has a collection of elements.
The keyFunction
passed into index
would be a Function
which just retrieves the property from a single element.
这篇关于Java - 如何根据其元素的属性分隔列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!