Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
I think that the array list version is easier to read and in general a collection is going to be easier to work with in Java.
The requirements don't mention that speed or memory are limited, so I didn't try to optimize my code for that. I think that in general best practices would say write the most readable and resuable code and if performance becomes an issue use a tool (profiler) to identify slow points (since the optimizer might actually correct something you assume is a problem).
You spend too much processing power creating an ArrayList to only convert it to an array. Why not declare the array?
I don't know... this would be a very, very minor speed improvement given that this algorithm is the worst in terms of speed.
You could compress lines 2 and 3 into one with one 'or' statement and improve speed.
Voted this one up for being more efficient than the indexOf solution.
I agree. All 'indexOf' type functions search the whole array for the supplied element and return the index it's currently in, like a for loop. Since you already go through numbers the size of the array (O(n)) and for each one you do the same with indexOf, you get O(n^2). The reduce solution, however, goes through the array only once, therefore being a O(n) solution.