【发布时间】:2016-03-01 14:40:03
【问题描述】:
我想知道是否可以在另一个数组中处理一个数组,我从来没有听说过这样的事情,我很好奇它是否可能,因为我现在正在编写一个小程序,我需要一些东西像这样! 一个例子(也许这可以解决,而不是在数组中使用数组): 我有两个这样的字符串数组:
public String[] stringArray1 = { "0", "1", "2", "3" }, stringArray2 = { "0", "1", "2", "3" };
现在我需要这样的东西:
public /*type?*/[] allArrays = { stringArray1, stringArray2 };
因为我需要使用 for 循环来访问它,而且我不想使用数千个 if 语句来访问 stringArrays(这只是我真实程序中的一个示例,有 100 个数组):
for(int i = 0; i < numberOfArrays/*100*/; i+=2)
test/*a rondom void*/(allArrays[i], allArrays[i+1]);
在我的程序中,总是有两个数组相连,这就是为什么我用 i 调用一个,用 i+1 调用一个......所以现在我的测试是这样的:
public void test(/*type?*/ test1, /*type?*/ test2)
{
//now i need to use test1 & test2 as string to f.e. like this:
if(test1[2].contains("1"))
//do something
}
【问题讨论】:
-
String[][],一个二维数组,实际上是一个包含数组的数组。 -
你的意思是
String[][],即二维数组?
标签: java