New dictionary

Jmnote (토론 | 기여)님의 2014년 5월 26일 (월) 01:24 판 (→‎JavaScript)
Associative arrays
hash map
hash table
Dictionary
NSDictionary
NSMutableDictionary

1 Bash

declare -A DICT
DICT["ID"]=102
DICT["Name"]="YONEZAWA Akinori"
DICT["Address"]="Naha, Okinawa"

2 C#

Hashtable ht = new Hashtable();
ht.Add("ID", "102");
ht.Add("Name", "YONEZAWA Akinori");
ht.Add("Address", "Naha, Okinawa");
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("ID", "102");
dic.Add("Name", "YONEZAWA Akinori");
dic.Add("Address", "Naha, Okinawa");
Dictionary<int, string> = new Dictionary<int, string> {
  { "ID", "102" },
  { "Name", "YONEZAWA Akinori" },
  { "Address", "Naha, Okinawa" }
};

3 Java

HashMap<String,Object> map = new HashMap<String,Object>();
map.put("ID", "102");
map.put("Name", "YONEZAWA Akinori");
map.put("Address", "Naha, Okinawa");
System.out.print("map", map.toString());
// {Name=YONEZAWA Akinori, ID=102, Address=Naha, Okinawa}

4 JavaScript

var dic = {
'ID' : '102',
'Name' : 'YONEZAWA Akinori',
'Address' : 'Naha, Okinawa'
};
console.log(dic);
// { ID: '102', Name: 'YONEZAWA Akinori', Address: 'Naha, Okinawa' }
var dic = {
ID : '102',
Name : 'YONEZAWA Akinori',
Address : 'Naha, Okinawa'
};
console.log(dic);
// { ID: '102', Name: 'YONEZAWA Akinori', Address: 'Naha, Okinawa' }
var dic = {}
dic.ID = '102';
dic.Name = 'YONEZAWA Akinori';
dic.Address = 'Naha, Okinawa';
var dic = {}
dic['ID'] = "102";
dic['Name'] = "YONEZAWA Akinori";
dic['Address'] = "Naha, Okinawa";
console.log(dic);
var dic = new Object();
dic['ID'] = "102";
dic['Name'] = "YONEZAWA Akinori";
dic['Address'] = "Naha, Okinawa";
console.log(dic);
// { ID: '102', Name: 'YONEZAWA Akinori', Address: 'Naha, Okinawa' }

5 Objective-C

NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
[dic setObject:@"102" forKey:@"ID"];
[dic setObject:@"YONEZAWA Akinori" forKey:@"Name"];
[dic setObject:@"Naha, Okinawa" forKey:@"Address"];

6 PHP

$dict = array(
  "ID" => 102,
  "Name" => "YONEZAWA Akinori",
  "Address"=> "Naha, Okinawa"
);

7 Python

dict = { 'ID' : 102, 'Name' : 'YONEZAWA Akinori', 'Address' : 'Naha, Okinawa' }
from pprint import pprint
dict = { }
dict['ID'] = 102
dict['Name'] = 'YONEZAWA Akinori'
dict['Address'] = 'Naha, Okinawa'
pprint( dict )
# {'Address': 'Naha, Okinawa', 'ID': 102, 'Name': 'YONEZAWA Akinori'}

8 같이 보기