java - How to remove elements from collection while iterating without iterator -
let's i've got list of strings (simplification)
fulllist = {a,b,c,d,a,d,c,b}
and want find couples like
coupleslist = {{a,a},{b,b}, ...}
the way i'm approaching problem @ moment is
- get first element
- use guava predicate find proper object
- what now?
i'm ending having 2 objects {a,a} can't remove them fulllist
because i'm not using "iterator" style of iterating (because i'm using guava predicate wouldn't work anyway - since don't have iterator pointer element find itarables.find(...)
function).
i want in "efficient" way well, want avoid multiple nested loops etc.
any ideas how approach problem more correctly/efficient way ? i'm bit stuck.
i create frequency count each of elements. in guava terms multiset. can create collection of pairs, , collection of singles. can done 1 pass of original list , 1 pass of frequency count map. i.e. o(n)
Comments
Post a Comment