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

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

问题描述

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

I have an array that looks like this

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

  • 在第一个括号中,我保存了类名
  • 第二次我保存了一个学生的 ID
  • 在第三个中,我保存了有关学生的信息(他的姓名、姓氏等).
  • 首先我分配所有班级名称,然后我为每个班级分配学生ID,然后我可以填写他们的信息.

    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";
    

    但它不起作用.

    或者有其他方法可以保存这三样东西吗?(班级名称、学生及其信息)

    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.

    因此,当您插入 School[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 数组中添加元素?

    开始时可以直接使用

    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 阵列.

    建议:声明一个包含三个Strings的类,创建带有这三个参数的构造函数,并通过Objects<将getter和setter放入获取和设置值/code>

    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天全站免登陆