Linear Run Time

I am trying to develop a method that can find common elements in a simple array with a linear run time O(n + m). This is an old school problem, i.e., no hashsets, hashtables, arraylists. Here is what I have so far.

The compiler will throw Class Cast Exception where I try to cast Object to Comparable in the commonElements method. I know that Object is the root of all classes, and I know why the compiler is doing this. However, is there a workaround to this. Also, is this a good algorithm for the test data below?

I like the O(n + m) approach for the commonElements method, but in this case, I may have to use a nested for loop O(n*m + n) because of the data structure in the test application. Any advice is greatly appreciated.

The method commonElements has to include Comparable[]. The argument of the method is taking an Object array. I adjust the statement from time to time, but normally, it will throw a Class Cast Exception. I am trying to find a workaround to this problem.

The [ character in [Ljava.lang.Integer refers to an array.
The compiler is complaining that the code is trying to cast an Integer object to an array of Integer objects.
The expression: collections[collectionsCount] is a single object, not an array.

I have one problem. I am probably overlooking something, but I cannot put my finger on it. I want to save the matches to a temporary array. When I run the test application, this information is generated.

Query is array 0
[]
[Ljava.lang.Comparable;@19ee1ac
Comparison: 12

The algorithm is linear, but I am getting an empty array. What am I doing wrong?

All right, NormR1. I think I have given up on the simple array linear solution for this data structure. What I am finding is that I need a deep transveral to review the subelements contained with each element of the data structure.

I am trying a hashSet. The code does find the common elements in linear time. I am just having trouble with casting the return statement of the common elements method. Hopefully, you can suggest what I can do to get around the class cast exception.