0
我想要一个方法或函数来使用Java中的索引数组获取数组的元素,但我不确定如何执行此操作。是否有可能从参数Java中的数组获取数组索引(这样getArrayIndex(theArray, [0, 1])
将返回theArray[0][1]
?从Java中的参数列表中获取数组索引
import java.util.*;
import java.lang.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Object[][] theArray = {{"Hi!"}, {"Hi!"}, {"Hi!", "Hi!"}};
Object index1 = getArrayIndex(theArray, [0, 0]) //this should return theArray[0][0]
Object[] index1 = getArrayIndex(theArray, [0]) //this should return theArray[0]
}
public static Object getArrayIndex(Object[] theArray, Object[] theIndices){
//get the object at the specified indices
}
}
System.arraycopy(java.lang.Object中,INT,java.lang.Object中,INT,INT)应该有所帮助。 – 2013-03-18 20:08:53
我假设你想要的签名是'公共静态对象getArrayIndex( Object [] [] theArray,Object [] theIndices){'(或者甚至更好,'pub lic静态对象getArrayIndex(Object [] [] theArray,int [] theIndices){')? – Noyo 2013-03-18 21:05:54