Java 3D数组赋值 [英] Java 3D array assign values

查看:166
本文介绍了Java 3D数组赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的数组

I have an array that looks like this

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




  • 在第一个括号中我保存了班级名称

  • 在第二个我保存学生的身份证

  • 在第三个我保存有关学生的信息(他的姓名,姓氏等)。

  • 首先我分配所有的班级名称,之后我将每个班级分配给学生证,然后我就可以填写他们的信息了。

    First I assign all the class names, after that I assign to every class its student ID and then I can fill in their information.

    我该怎么办?我试过它,例如

    How can I do it? I tried it with for example

    School[i] = "A1";
    

    但它不起作用。

    编辑:或者还有另一种方法来保存这三件事吗? (班级名称,学生及其iformation)

    Or is there an other way to save this all 3 things? (class name, its students and its iformation)

    推荐答案

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

    考虑具有3维度的数字。

    Consider figure which has 3 Dimension.

    因此,当您插入学校[0] [0] [0] =A1时,表示您已在0,0,0位置输入元素。

    So when you insert School[0][0][0]="A1" it means you have entered element at 0,0,0 position.

    从0,0,0开始,这将上升到位置1000,20,5。

    From 0,0,0 this will move upto the 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"
    ......
    

    在3D数组元素中看起来像

    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.
    






    现在如何在3D中添加元素数组?

    在开始时你可以直接使用

    At Start you can directly use

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

    在您的情况下,这是一项非常繁琐的任务,因为您希望在每个位置插入详细信息。
    因为你有 1000 记录。

    This is very tedious task in your case as you want to insert details at every position. As you have 1000 records.

    你的数组将有这样的元素

    Your array will have elements like this

    注意建议不要将3D数组用于此目的。

    建议声明一个包含三个的字符串使用这三个参数创建构造函数,并通过对象

    Suggestion:Declare a class with three Strings create constructor with this three parameters and put getter and setters to get and set values via Objects

    这篇关于Java 3D数组赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆