How do I create a 2d array made of 2d int arrays in java?

Laurena

I want to create a 2d array that is made of smaller 2d integer arrays, to overall make a matrix graph. Instead of storing integers in the bigger array I would store 2d integer arrays.

Edit: I think drew the array I want incorrectly. What I meant was I want to create a grid (matrix - 2d array) where inside each cell of the grid instead of there being stored a int, boolean, etc. I would like to store a 2d int array in each cell of the grid.

I was thinking something like int[int[][]][int[][]]. But realized that wouldn't work since the outer array isn't an integer array, it is just a general array made of integer arrays.

I found codes in other questions here that have a 2d array of objects (ex. room[][]) but I don't think that would be necessary since the array I'm trying to make is made of int[][] arrays, correct?

So how could I got about this?

Thanks in advance!

VN'sCorner

In Java multi-dimentional arrays are implemented as array of arrays approach and not matrix form. To implement the data structure provided in the request array has to be implemented as below,

Data Structure :

{{{0,1}, {{0,1},
  {2,3}}, {2,3}},
 {{0,1}, {{0,1},
  {2,3}}, {2,3}}}

Array Declaration and assignment :

public class MyClass {
    public static void main(String args[]) {

      int[][][][] q =new int[2][2][2][2];

      q[0][0][0][0] = 0;
      q[0][0][0][1] = 1;
      q[0][0][1][0] = 0;
      q[0][0][1][1] = 1;
      q[0][1][0][0] = 2;
      q[0][1][0][1] = 3;
      q[0][1][1][0] = 2;
      q[0][1][1][1] = 3;

      q[1][0][0][0] = 0;
      q[1][0][0][1] = 1;
      q[1][0][1][0] = 0;
      q[1][0][1][1] = 1;
      q[1][1][0][0] = 2;
      q[1][1][0][1] = 3;
      q[1][1][1][0] = 2;
      q[1][1][1][1] = 3;
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I swap columns with a specific indexes in java 2d arrays?

How can I convert an 2D int array into a 2D String array with Streams?

How do I do a deep copy of a 2d array in Java?

How do I create a primitive two-dimensional (2d) array of doubles in Clojure?

How do I create 2D arrays based on sparse column matrix parameters in JAVA

How to Create 2D arrays in smalltalk

How can i create 2d array with list comprehesion?

How do I pass in a 2d array I made from main into another function in C

How do I split an Array into 10 individual 2D arrays?

Create 2D array with 2 int arrays

How do I create a 2d array with strings?

How to Create ArrayList of 2D Arrays

How do I create a pointer to a 2D array of pointers - C

How can I manipulate 2D arrays in Java?

Can I use Arrays.fill with a 2d array? If so how do I do that?

How can I create 2D array dynamically?

How to make a 2D array of 2D arrays

ArrayList of Arrays to 2d Array in Java

How do I split a 2D array into smaller 2D arrays, of variable size?

How do i convert a Set into 2D array in java?

How do I insert a row into a 2D array in java?

How do I create a 2D array?

How do i sort a 2D array or multiple arrays by the length of the array using bubble sort

How do I create a table using 2D array in Java?

how to split a 2d array into multiple 2d arrays of different sized in java

How to concatenate numpy arrays to create a 2d numpy array

How do I use a loop to multiply a row of a 2D array to the column of a second 2D array, and etc in Java?

How do I combine inner arrays of a 2D array based on first identical value?

How to eliminate nested arrays to create a "clean" 2d array

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive