Let's say I have a list (EG: LinkedList<SomeObject>
that contains elements ordered by a certain attribute (EG: SomeObject.someValue()
). This attribute can and usually does repeat often/it isn't unique, BUT is never null.
Is there a convenient way to divide this into multiple Lists, each list containing only its equal in cardinal order? Also, can this be done with only once iteration of the list? For example, the original list:
1, 1, 1, 2, 2, 3, 3, 3
The desired lists from this:
1, 1, 1
2, 2,
3, 3, 3
Not too convenient, but:
equals(..)
, and be careful with null
), then create a new List
, or use list.subList(groupStart, currentIdx)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With