public class Memory3 { static int[][] N = new int[0][]; int NLengh; void add(int[] i) { int[][] N22 = new int[1][]; boolean isSorted = false; int[][] N3 = new int[NLengh + 1][]; N3 = Arrays.copyOf(N, N3.length); N3[N3.length - 1] = i; NLengh++; N = N3; if (N.length != 1) { while (!isSorted) { isSorted = true; for (int k = 1; k < NLengh; k++) { if (N[NLengh - 1 - k][0] >= N[NLengh - k][0]) { isSorted = false; N22[0] = N[NLengh - 1 - k]; N[NLengh - 1 - k] = N[NLengh - k]; N[NLengh - k] = N22[0]; } } } } } public static void main(String[] args) { Memory3 M = new Memory3(); int[][] N22 = new int[6][]; N22[0] = new int[]{7, 7, 3}; N22[1] = new int[]{6, 8, 6, 4}; N22[2] = new int[]{5, 2, 6, 5}; N22[3] = new int[]{3, 8, 6, 7}; N22[4] = new int[]{1, 2, 6, 2}; N22[5] = new int[]{0, 7, 6, 4, 8}; for (int s2 = 0; s2 < N22.length; s2++) { M.add(N22[s2]); } for (int r2 = 0; r2 < N.length; r2++) { for (int r = 0; r < N[r2].length; r++) { System.out.println("N[" + r2 + "][" + r + "]" + N[r2][r] + ""); } System.out.println("\n"); } } } It is necessary that I could transfer arrays of various dimensions to the add method and not just one-dimensional int arrays and already in the array method to increase the number of elements (references) to arrays. maybe use a generalization? Thank.
Objectthen you can transfer anything. Generics with arrays work poorly. You can create your own class and hide in it the logic of access to the elements. - talexisInstance()to help). If the dimension is greater than or equal to the current one, it is still clear what to do. And what to do with a smaller dimension, for me personally, is a big question. - Anton MArrayOrObject, which by get checks whether the array is created, otherwise it returns an object. But again, somehow we have to work with this ... - Anton M