Java中的多维数组 [英] Multi-dimensional arrays in Java

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

问题描述

我正在准备OCAJP考试,我在java中遇到了多维数组的问题.在观看了 YouTube 上的视频教程后,我想我对它的工作原理有所了解.它说以下语句创建两个二维数组和一个数组来保存两个数组.因此它是一个三维数组.

I am preparing for OCAJP exam, I got a problem with the multi-dimensional arrays in java. After go through a video tutorial on YouTube, I think I got an idea about how it works. It says the following statement creates two double dimensional arrays and one array to hold both arrays. Hence it is a three dimensional array.

int arr[][][] = new int[2][4][3];

所以我想确认一下,如果我想要一个五维数组,这个语句可以做到.

So I want to get confirmed, that if I want a five dimensional array, this statement would do it.

 int arr[][][] = new int[4][4][3];

推荐答案

尝试以几何方式对其进行可视化.

Try to visualise it geometrically.

  • 一维数组只是一个列表:new int[2]

二维数组是一个矩形网格(或列表列表):new int[2][3]

A 2-dimensional array is a rectangular grid (or a list of lists): new int[2][3]

一个 3 维数组是一个长方体(或一个矩形列表,或一个列表列表列表):new int[2][3][4]

A 3-dimensional array is a cuboid (or a list of rectangles, or a list of lists of lists): new int[2][3][4]

在这之后它变得更难了,但是:

After this it gets harder, but :

  • 一个 4D 数组是一个长方体列表(一个列表列表列表)new int[2][3][4][5]

一个 5D 数组是一个长方体网格(一个列表列表列表列表):new int[2][3][4][5][6]

a 5D array is a grid of cuboids (a list of lists of lists of lists of lists): new int[2][3][4][5][6]

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

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