Recently, when doing an assignment for college, one of the things I came across was sorting and searching a 2D-array.
Using Arrays.sort(example);
or Arrays.binarySearch(example, "xyz");
returns an error:
example cannot be cast to java.lang.Comparable
Instead of binary search, I had to use nested for loops, though I would have liked to do it the efficient way.
Another problem I had was using Arrays.asList(example).contains("xyz");
, which never seemed to work. I then used System.out.println(Arrays.asList(example));
to check what was wrong. This is what I got:
[[I@1575c7e, [I@795f24, [I@554210, [I@16433e4, [I@18ada25, [I@f7bd29, [I@a3cf3e, [I@7af3e0, [I@21151e, [I@1f194d9]
What is that and most importantly what is the best way to get around these problems?
And a follow up question - Why do some errors (like example cannot be cast to java.lang.Comparable
only appear once the program is run, not when it is compiled?
Any help is very much appreciated.