次のobjective-cコードがあります
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:names forKeys:dates];
名前と日付は NSMutableArrays です
このコードに相当するJavaは何ですか?
ありがとう
日付配列要素が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);