I'm assuming you posted before I submitted my last revision. I also changed the Object arrays to int arrays in the driver. I am now getting the correct elements just not enough comparisons.
Joined: Oct 04, 2012
Finally figured it out.... 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.
The following elements were common among all arrays:
[[1, 2, 3, 4, 5, 16, 22, 23, 25, 28]]
Additionally, there were a total of 40 comparisons made between the arrays.
[Ljava.lang.Comparable;@3ee284 <<<<<<---- not sure why this though??
Joined: Oct 04, 2012
"hashset"....And from your suggestions, though I had no idea how to implement it at first. (I'm referring to the comments I left in the code).
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.
PS: Please remember what I said about DontWriteLongLines. I've broken yours up again, but this is the last time.
Isn't it funny how there's always time and money enough to do it WRONG?