Java多维数组上的多种类型
据我所知,多维Java数组上只能存储一种类型的对象/文字。
From what I know, only one type of object/literal can be stored on a multi-dimensional Java array.
例如,在2维数组a [] []上,我无法在a [0]上存储
a Type-1数组[1]上的类型和类型2数组,除非类型1和类型2之间存在多态关系。 Type-2,我在那里使用了。
so for instance, on a 2-dim'l array a[][], I can not store a Type-1 array on a[0] and Type-2 array on a[1] unless there's some polymorphic relationship between Type-1 & Type-2 and I put it into use there.
我希望确认没有办法解决此问题。因此,我无法以某种方式在a [0]上放置一个int数组,在a [1]上放置一个char数组-Java数组是单一类型。
I'm looking to verify that there's no way to get around this. so, I cannot somehow put an int array on a[0], a char array on a[1]-- Java arrays are single-type.
我是注意,我可以声明2个并行数组-一个int []和一个char []即可解决。
I'm aware that I can declare 2 parallel arrays-- one int[] and one char[] and that solves it.
谢谢。
// ============= =======
//=====================
编辑:好的旧对象类可以解决它-如下所示,是有用的答案。谢谢您的意见。
The good old object class solves it-- as the useful answers below pointed out. Thank you for your input.
您可以使用对象的数组
:
Object[] x = new Object[2];
x[0] = new Integer[3];
x[1] = new String[3];