You can solve your problem using :
public static void main(String[] args) {
Integer[][] a = {{3, 1}, {0, 2}};
List<Integer> list = new ArrayList<>();
for (Integer[] i : a) {//<--convert the 2d to list-------------------------(1)
list.addAll(Arrays.asList(i));
}
Collections.sort(list);//<--sort this list---------------------------------(2)
Integer[][] result = new Integer[a.length][];//create new 2d array---------(3)
int k = 0;
for (int i = 0; i < a.length; i++) {//loop throw the original array--------(4)
//creae temp array with the same size of each 1d array-----------------(5)
Integer[] temp = new Integer[a[i].length];
//loop and fill temp array with elements of the list-------------------(6)
for (int j = 0; j < a[i].length; j++) {
temp[j] = list.get(k);
k++;
}
result[i] = temp;//add the temp to the new array-----------------------(7)
}
System.out.println(Arrays.deepToString(result));//print the new array
}
example
input output
{{3, 1}, {0, 2}} [[0, 1], [2, 3]]
{{3, 1, 5}, {0, 2}} [[0, 1, 2], [3, 5]]
{{3, 1, 5}, {0, 5}, {3, 7, 5}, {10, 9, 11}} [[0, 1, 3], [3, 5], [5, 5, 7], [9, 10, 11]]
Note this solution will assure the same length of each node of the original array.