Ian Mcloud wrote:Finally figured it out....
Well done. And I notice you've now included a HashSet, in which case you might be interested in its
retailAll() method - it'll reduce your code even more.
But one last thing. Any ideas on how I can include duplicate elements? I've sorted the arrays and managed to find all common elements, but I want multiple values of a common element. Such as, 28, which appears in only two sets but should be printed twice in the common set.
Hunh? I thought you were only interested in elements that were common to
all arrays. When I was talking about duplicates, I meant including two copies of an element in your result only if ALL arrays have at least two of them.
And the only way I know to do that is:
1. Count occurrences of each
distinct value in each array.
2. Eliminate values where any of the counts is 0;
3. If the minimum count is > 1, include
that number of copies in the output.
And for that, you will almost certainly need a Map (unless you want to write a lot of unnecessary code).
If that's not what you want, I think you'll have to describe your requirements a bit more clearly.
I see. So cast it somehow?
No, no, no. In fact, your program has far too many casts in it already (you could actually write it without a single one). Casts are
evil, and to be avoided at all costs.
Winston
PS: Please remember what I said about
DontWriteLongLines. I've broken yours up
again, but this is the last time.