"New dictionary"의 두 판 사이의 차이

52번째 줄: 52번째 줄:
==JavaScript==
==JavaScript==
[[분류: JavaScript]]
[[분류: JavaScript]]
*literal notation
<source lang='javascript'>
<source lang='javascript'>
var dic = {
var dic = {
81번째 줄: 82번째 줄:
dic['Name'] = "YONEZAWA Akinori";
dic['Name'] = "YONEZAWA Akinori";
dic['Address'] = "Naha, Okinawa";
dic['Address'] = "Naha, Okinawa";
console.log(dic);
</source>
;constructor notation
<source lang='javascript'>
var dic = new Object();
dic.ID = "102";
dic.Name = "YONEZAWA Akinori";
dic.Address = "Naha, Okinawa";
console.log(dic);
console.log(dic);
</source>
</source>
89번째 줄: 98번째 줄:
dic['Address'] = "Naha, Okinawa";
dic['Address'] = "Naha, Okinawa";
console.log(dic);
console.log(dic);
// { ID: '102', Name: 'YONEZAWA Akinori', Address: 'Naha, Okinawa' }
</source>
</source>



2014년 5월 26일 (월) 01:27 판

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

  • literal notation
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);
var dic = {}
dic.ID = '102';
dic.Name = 'YONEZAWA Akinori';
dic.Address = 'Naha, Okinawa';
console.log(dic);
var dic = {}
dic['ID'] = "102";
dic['Name'] = "YONEZAWA Akinori";
dic['Address'] = "Naha, Okinawa";
console.log(dic);
constructor notation
var dic = new Object();
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);

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 같이 보기