0

次のような配列があります。

this.ntpServers[0][0] = "Global";
this.ntpServers[0][1] = "pool.ntp.org";
this.ntpServers[1][0] = "Africa";
this.ntpServers[1][1] = "africa.pool.ntp.org";
this.ntpServers[2][0] = "Asia";
this.ntpServers[2][1] = "asia.pool.ntp.org";
this.ntpServers[3][0] = "Europe";
this.ntpServers[3][1] = "europe.pool.ntp.org";
this.ntpServers[4][0] = "North America";
...
this.ntpServers[85][0] = ...
this.ntpServers[85][1] = ...

別の文字列に国があり、次のコードを使用してリストに存在するかどうかを比較しようとしていますが、真でなければならないときに真を返しません。「アジア」にチェックを入れると、本当です。しかし、何かが間違っています。

gettedCountry は文字列です

public int existNTP(String[][] list) {

    if(Arrays.asList(list).contains(gettedCountry)){

        Log.i("Found", "Found");

        }

        return position;
    }

お手伝いありがとうございます。

4

2 に答える 2

1

適切なオブジェクトを作成して、2 次元配列をリストに変換します (推奨)

また

配列を反復処理します。

int position = 0;
for (String[] entry : ntpServers) {
  if (entry[0].equals(country)) return position;
  ++position;
}

return -1; // Not found is an invalid position like -1
于 2013-09-08T09:54:08.767 に答える
0

Arrays.asList(list)ArrayListString[]notを返しStringます。最初の項目を確認する必要がある場合:

ArrayList<String[]> arr=Arrays.asList(list);

for(String[] arry : arr){
  if(arry[0].equals(gettedCountry)) /* Do your stuff */;
}
于 2013-09-08T09:53:49.837 に答える