This can be solved in a straightforward manner using streams:
int[][] dp = {{5,9}, {6,7}, {4, 21}, {7, 12}};
int max = Arrays.stream(dp).mapToInt(a -> a[1]).max().orElseThrow();
This streams over the outer array, maps each inner array to the second element of that array, then returns the maximum element of those mapped values.
Detailed breakdown
Arrays.stream(dp) - Returns a Stream<int[]> of the array's elements.
mapToInt(a -> a[1]) - Applies a ToIntFunction<int[]> to each element of the Stream<int[]>, returning an IntStream of those results. This uses function a -> a[1], which takes an array and returns the element at index 1.
max() - Returns the maximum int in the IntStream as an OptionalInt. This OptionalInt will contain the max value (unless the stream is empty, in which case it'll be an empty OptionalInt).
orElseThrow - Returns the int value in the OptionalInt, or throws NoSuchElementException if the OptionalInt is empty.
forloop should be super efficient, though perhaps a bit more verbose (and less potentially parallelizable) than other approaches. For instance, you're unlikely to find a solution that's more efficient thanint max = Integer.MIN_VALUE; for (int[] arr : dp) { max = Math.max(arr[1], max); }