I want to get the code below to run, but at this point Collections.sort(c) throws java.lang.ClassCastException.
Basically, I want to get a max or max by index from a 2d array. I have it working when I do manual 2d array traversal, but I'm hoping to make something faster. Any relevant input is much appreciated.
Here is what I have:
In future, if you get an exception please include the full exception message and stack trace in your post.
The addAll() method won't add every int value in the 2D array to the ArrayList, it will add each of the 1D arrays that make up the 2D array and as int arrays do not implement Comparable the sort fails.
I have noticed you haven't used generics when declaring your ArrayList, if you had the code would have failed to compile - a good reason to use generics.
If you want to add all the int values use a for-each loop to iterate over the first dimension of matrix and add each returned 1D array to the collection.