This will be your first method:
public static int[] convert1dToInt (boolean[] x) {
Just repeat your code - I did not have much time, since this is my lunch break, so I do not know if everything is correct, but the method should correspond:
public static int[][] convert2dToInt (boolean[][] x) { int[][] y = new int[x.length][]; for (int a = 0; a < x.length; a++) { y[a] = convert1dToInt (x[a]) ; } return y; }
Well, this solution was not the answer to the problem, since I did not read exactly what was asked. Sorry about that. As far as I know, a generic method is not possible as long as you work with primitive data types. This is because you cannot add int [] as a member for int []. Therefore, you should work with Object [], Boolean [] and Integer [], but I do not know how you want to work with this. I donโt think itโs wise to write such a method, because when you can transform such a data structure as you want goals to be available. Since you do not know how many dimensions your array will have, you will not be able to write general methods for accessing members. I will try to write a solution for this, since I want to know if I will find another possible solution. Is it right that the question is, is this possible, and if not, is it reasonable?
I think we can find a better solution for this if you tell us that you want to have this code. As I said, when I have more time, I will try to find another solution.
wstein
source share