1

次のobjective-cコードがあります

 NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:names forKeys:dates];

名前と日付は NSMutableArrays です

このコードに相当するJavaは何ですか?

ありがとう

4

1 に答える 1

1

日付配列要素がLong(Java日付)であり、名前配列要素が文字列であると仮定します。

Map<Long, String> dictionary = new HashMap<Long, String>();
for (int idx = 0; i < dates.length; ++idx) {
    dictionary.put(dates[idx], names[idx]);
}

HashMapはNSDictionaryのように不変ではないことに注意してください。これが受け入れられない場合は、次のように使用します。

Collections.unmodifiableMap(dictionary);
于 2012-07-17T08:55:03.020 に答える