Java 3D array assignment

I have an array that looks like this

static String[][][] School= new String[1000][20][5];

>In the first bracket, I saved the class name @ H_ 403_ 5 @ > in the second part, I saved the student's ID card @ H_ 403_ 5 @ > in the third part, I save information about the student (his name, last name, etc.)

First I assign all class names, then I assign each class to student ID, and then I can fill in their information

What shall I do? I tried this example

School[i] = "A1";

But it doesn't work

Editor: or is there another way to save these three things? (class name, students and their information)

Solution

static String[][][] School= new String[1000][20][5];
static String[][][] School= new String[1000][20][5];

Consider a graph with 3 dimensions

Therefore, when you insert school [0] [0] [0] = "A1", it means that you have entered an element at position 0,0

Starting from 0,0, this will rise to position 1000,20,5

You can insert like this, but you have so many elements

School[0][0][0]="A1"
School[0][0][1]="A2"
School[0][0][2]="A3"
.....
School[0][1][0]="B1"
School[0][1][1]="B2"
School[0][1][2]="B3"
......

In 3D, array elements look like

int[3][4][2] array3D
// means Three (4x2) 2 Dimensional Arrays 

 int[4][2]
 //means Four 1 dimensional arrays.

Now how do I add elements to the 3D array?

At the beginning, you can use it directly

int[][][] threeDArray = 
    {  { {1,2,3},{ 4,5,6},{ 7,8,9} },{ {10,11,12},{13,14,15},{16,17,18} },{ {19,21},{22,23,24},{25,26,27} } };

In your case, this is a very cumbersome task because you want to insert details at each location@ H_ 403_ 5@ because you have 1000 records

Your array will have such elements

Note: it is not recommended to use 3D arrays for this purpose

Suggestion: use these three parameters to declare a class with three strings, create a constructor, and set getters and setters to get and set values through objects

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>