具有不同类型的二维数组 [英] Two dimensional array with different types
本文介绍了具有不同类型的二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个:
private float dir = 0f;
private boolean ch = true;
private String = "No";
private int aB = 5;
我现在如何用这个值制作一个二维数组?
例如 array1 [] []
:
How can I now, make an two dimensional array with this values?
e.g. array1[][]
:
{ {0f, "true", "No", 5} }
还是我应该像这样创建一个数组?
Or should I make an array like this?
private String array1[][];
将所有值另存为 String
,然后分析
每个项目?
Saving all values as a String
and then parse
each item?
但是我认为这不是一个很好的编程。
But I think, that this is not a good programming.
推荐答案
您可以使用抽象数组,即使用Object作为类型的IE。
You can use an abstract array, IE using Object as the type.
Object array1[][];
但是,这看起来更像是您真正想要一堂课。
However this looks more like you really want a class.
class MyObject {
private float dir;
private boolean ch;
private String str;
private int aB;
// getters and setters omitted
}
,然后创建一个数组或具有以下内容的集合: MyObject [] array1
。如果可以存储对象,通常这是更好的设计。
and then create an Array or Collection with this: MyObject[] array1
. This is usually better design if you can store Objects.
这篇关于具有不同类型的二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文