ここに私の問題があります: -配列名を配列に格納する方法は?
私は文字列として配列名(整数)を含む2つの文字列配列を持っています。 これで、各整数配列を残りの配列と比較する必要があります。
は、私は、配列
int[] data;
data1 = new int[] {10,20,30,40,50,60,71,80,90,91};
data2 = new int[] {10,20,30,40,50,60,71,80,90,91};
data3 = new int[] {10,20,30,40,50,60,71,80,90,91};
data4 = new int[] {10,20,30,40,50,60,71,80,90,91};
data5 = new int[] {10,20,30,40,50,60,71,80,90,91};
/*Now divide the above data into two parts like data1 and data2 is in one side and other content is other side and each array will compare with other set of arrays. i.e. array data1 will compare with array data3, data4, data5. and same for data2 array */
String [] str= new String[2];
String [] str1= new String[3];
str[0]="data"; //Name Of the first array.
str[1]="data2"; //This is also other array name
str1[0]="data3";
str1[1]="data4";
str1[2]="data5";
//Now I need to call a function passing array name as the parameter.
for(int i=0;i<str.length();i++)
{
for(int j=0;j<str1.length();j++)
{
compare(str[i],str1[j]); //this is error part
//and the function definition is
public void compare(int[] x1, int[] x2)
{//compare code
}
しかし、取得中にエラーがあるとします: - 互換性のない型:文字列は、あなたがint[]
を受け入れる方法にString
を渡そうとしている[]
マップを使用します。 –
Walfrat
私はあなたが 'compare(str [0])'の代わりに 'compare(data)'をやろうと思っています。 –