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

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(사용자 2명의 중간 판 44개는 보이지 않습니다)
2번째 줄: 2번째 줄:
[[분류: Dictionary]]
[[분류: Dictionary]]
;Associative arrays
;Associative arrays
;Hash
;hash map
;hash map
;hash table
;hash table
;Dictionary
;Dictionary
;dict
;NSDictionary
;NSDictionary
;NSMutableDictionary
;NSMutableDictionary
10번째 줄: 12번째 줄:
==Bash==
==Bash==
[[분류: Bash]]
[[분류: Bash]]
<source lang='bash'>
<syntaxhighlight lang='bash'>
declare -A DICT
declare -A MEMBER
DICT["ID"]=102
MEMBER=(["ID"]=102 ["Name"]="YONEZAWA Akinori" ["Address"]="Naha, Okinawa")
DICT["Name"]="YONEZAWA Akinori"
 
DICT["Address"]="Naha, Okinawa"
for k in "${!MEMBER[@]}"; do
</source>
  echo "[$k] ${MEMBER[$k]}"
done
# [Address] Naha, Okinawa
# [ID] 102
# [Name] YONEZAWA Akinori
</syntaxhighlight>
<syntaxhighlight lang='bash'>
declare -A MEMBER
MEMBER["ID"]=102
MEMBER["Name"]="YONEZAWA Akinori"
MEMBER["Address"]="Naha, Okinawa"
</syntaxhighlight>
<syntaxhighlight lang='bash'>
declare -A MEMBER
MEMBER=(["ID"]=102)
MEMBER+=(["Name"]="YONEZAWA Akinori")
MEMBER+=(["Address"]="Naha, Okinawa")
</syntaxhighlight>


==C#==
==C#==
[[분류: Csharp]]
[[분류: Csharp]]
<source lang='csharp'>
<syntaxhighlight lang='csharp'>
Hashtable ht = new Hashtable();
Hashtable member = new Hashtable();
ht.Add("ID", "102");
member.Add("ID", "102");
ht.Add("Name", "YONEZAWA Akinori");
member.Add("Name", "YONEZAWA Akinori");
ht.Add("Address", "Naha, Okinawa");
member.Add("Address", "Naha, Okinawa");
</source>
</syntaxhighlight>
<source lang='csharp'>
<syntaxhighlight lang='csharp'>
Dictionary<string, string> dic = new Dictionary<string, string>();
Dictionary<string, string> member = new Dictionary<string, string>();
dic.Add("ID", "102");
member.Add("ID", "102");
dic.Add("Name", "YONEZAWA Akinori");
member.Add("Name", "YONEZAWA Akinori");
dic.Add("Address", "Naha, Okinawa");
member.Add("Address", "Naha, Okinawa");
</source>
</syntaxhighlight>
<source lang='csharp'>
<syntaxhighlight lang='csharp'>
Dictionary<int, string> = new Dictionary<int, string> {
Dictionary<int, string> member = new Dictionary<int, string> {
   { "ID", "102" },
   { "ID", "102" },
   { "Name", "YONEZAWA Akinori" },
   { "Name", "YONEZAWA Akinori" },
   { "Address", "Naha, Okinawa" }
   { "Address", "Naha, Okinawa" }
};
};
</source>
</syntaxhighlight>


==Java==
==Java==
{{참고|자바 HashMap}}
[[분류: Java]]
[[분류: Java]]
<source lang='java'>
<syntaxhighlight lang='java'>
HashMap<String,Object> map = new HashMap<String,Object>();
HashMap<String,Object> member = new HashMap<String,Object>();
map.put("ID", "102");
member.put("ID", "102");
map.put("Name", "YONEZAWA Akinori");
member.put("Name", "YONEZAWA Akinori");
map.put("Address", "Naha, Okinawa");
member.put("Address", "Naha, Okinawa");
System.out.print("map", map.toString());
System.out.println( member );
// {Name=YONEZAWA Akinori, ID=102, Address=Naha, Okinawa}
// {Address=Naha, Okinawa, ID=102, Name=YONEZAWA Akinori}
</source>
</syntaxhighlight>


==JavaScript==
==JavaScript==
[[분류: JavaScript]]
[[분류: JavaScript]]
<source lang='javascript'>
{{소스헤더|literal notation}}
var dic = {
<syntaxhighlight lang='javascript'>
var member = {
'ID' : '102',
'ID' : '102',
'Name' : 'YONEZAWA Akinori',
'Name' : 'YONEZAWA Akinori',
'Address' : 'Naha, Okinawa'
'Address' : 'Naha, Okinawa'
};
};
console.log(dic);
console.log(member);
// Object {ID: "102", Name: "YONEZAWA Akinori", Address: "Naha, Okinawa"}  
// { ID: '102', Name: 'YONEZAWA Akinori', Address: 'Naha, Okinawa' }
</source>
</syntaxhighlight>
<source lang='javascript'>
<syntaxhighlight lang='javascript'>
var dic = new Object();
var member = {
dic['ID'] = "102";
ID : '102',
dic['Name'] = "YONEZAWA Akinori";
Name : 'YONEZAWA Akinori',
dic['Address'] = "Naha, Okinawa";
Address : 'Naha, Okinawa'
console.log(dic);
};
// Object {ID: "102", Name: "YONEZAWA Akinori", Address: "Naha, Okinawa"}
console.log(member);
</source>
</syntaxhighlight>
{{소스헤더|dot notation}}
<syntaxhighlight lang='javascript'>
var member = {}
member.ID = '102';
member.Name = 'YONEZAWA Akinori';
member.Address = 'Naha, Okinawa';
console.log(member);
</syntaxhighlight>
<syntaxhighlight lang='javascript'>
var member = new Object();
member.ID = "102";
member.Name = "YONEZAWA Akinori";
member.Address = "Naha, Okinawa";
console.log(member);
</syntaxhighlight>
{{소스헤더|bracket notation}}
<syntaxhighlight lang='javascript'>
var member = {}
member['ID'] = "102";
member['Name'] = "YONEZAWA Akinori";
member['Address'] = "Naha, Okinawa";
console.log(member);
</syntaxhighlight>
<syntaxhighlight lang='javascript'>
var member = new Object();
member['ID'] = "102";
member['Name'] = "YONEZAWA Akinori";
member['Address'] = "Naha, Okinawa";
console.log(member);
</syntaxhighlight>


==Objective-C==
==Objective-C==
[[분류: Objective-C]]
[[분류: Objective-C]]
<source lang='objc'>
<syntaxhighlight lang='objc'>
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
NSMutableDictionary *member = [[NSMutableDictionary alloc] init];
[dic setObject:@"102" forKey:@"ID"];
[member setObject:@"102" forKey:@"ID"];
[dic setObject:@"YONEZAWA Akinori" forKey:@"Name"];
[member setObject:@"YONEZAWA Akinori" forKey:@"Name"];
[dic setObject:@"Naha, Okinawa" forKey:@"Address"];
[member setObject:@"Naha, Okinawa" forKey:@"Address"];
</source>
</syntaxhighlight>


==PHP==
==PHP==
[[분류: PHP]]
[[분류: PHP]]
<source lang='php'>
{{참고|PHP array()}}
$dict = array(
<syntaxhighlight lang='php'>
$member = array(
  "ID" => 102,
  "Name" => "YONEZAWA Akinori",
  "Address"=> "Naha, Okinawa"
);
</syntaxhighlight>
<syntaxhighlight lang='php'>
$member = [
  "ID" => 102,
  "Name" => "YONEZAWA Akinori",
  "Address"=> "Naha, Okinawa"
];
</syntaxhighlight>
<syntaxhighlight lang='php'>
$member = array();
$member['ID'] = 102;
$member['Name'] = "YONEZAWA Akinori";
$member['Address'] = "Naha, Okinawa";
</syntaxhighlight>
<syntaxhighlight lang='php'>
$member = [];
$member['ID'] = 102;
$member['Name'] = "YONEZAWA Akinori";
$member['Address'] = "Naha, Okinawa";
</syntaxhighlight>
 
==Python==
[[분류: Python]]
<syntaxhighlight lang='Python'>
d = dict(a=1, b=2, c=3)
print( d )
# {'b': 2, 'c': 3, 'a': 1}
</syntaxhighlight>
<syntaxhighlight lang='Python'>
member = { 'ID' : 102, 'Name' : 'YONEZAWA Akinori', 'Address' : 'Naha, Okinawa' }
</syntaxhighlight>
<syntaxhighlight lang='Python'>
from pprint import pprint
member = { }
member['ID'] = 102
member['Name'] = 'YONEZAWA Akinori'
member['Address'] = 'Naha, Okinawa'
pprint( member )
# {'Address': 'Naha, Okinawa', 'ID': 102, 'Name': 'YONEZAWA Akinori'}
</syntaxhighlight>
 
==Ruby==
[[분류: Ruby]]
{{소스헤더|string key}}
<syntaxhighlight lang='Ruby'>
member = {
   "ID" => 102,
   "ID" => 102,
   "Name" => "YONEZAWA Akinori",
   "Name" => "YONEZAWA Akinori",
   "Address"=> "Naha, Okinawa"
   "Address"=> "Naha, Okinawa"
}
puts member
# {"ID"=>102, "Name"=>"YONEZAWA Akinori", "Address"=>"Naha, Okinawa"}
</syntaxhighlight>
<syntaxhighlight lang='Ruby'>
member = {}
member['ID'] = 102
member['Name'] = 'YONEZAWA Akinori'
member['Address'] = 'Naha, Okinawa'
puts member
# {'Address': 'Naha, Okinawa', 'ID': 102, 'Name': 'YONEZAWA Akinori'}
</syntaxhighlight>
<syntaxhighlight lang='Ruby'>
member = Hash.new
member['ID'] = 102
member['Name'] = 'YONEZAWA Akinori'
member['Address'] = 'Naha, Okinawa'
puts member
# {'Address': 'Naha, Okinawa', 'ID': 102, 'Name': 'YONEZAWA Akinori'}
</syntaxhighlight>
{{소스헤더|symbol key}}
<syntaxhighlight lang='Ruby'>
member = {
  ID: 102,
  Name: "YONEZAWA Akinori",
  Address: "Naha, Okinawa"
}
print member
# {:ID=>102, :Name=>"YONEZAWA Akinori", :Address=>"Naha, Okinawa"}
</syntaxhighlight>
== Perl ==
[[분류: Perl]]
<syntaxhighlight lang='perl'>
my %month = (
"January" => "1월",
"February" => "2월",
"March" => "3월",
"April" => "4월",
"May" => "5월",
"June" => "6월",
"July" => "7월",
"August" => "8월",
"September" => "9월",
"October" => "10월",
"November" => "11월",
"December" => "12월"
);
);
</source>


==See also==
$month{"January"} = "일월";
$month{"March"} = "삼월";
 
foreach my $key (keys %month) {
my $value = $month{$key};
print "$key : $value\n";
}
#February : 2월
#December : 12월
#June : 6월
#July : 7월
#November : 11월
#April : 4월
#May : 5월
#January : 일월
#August : 8월
#October : 10월
#March : 삼월
#September : 9월
</syntaxhighlight>
 
==같이 보기==
*[[array]]
*[[array]]
*[[2d array]]
*[[array_combine]]
*[[array_combine]]
*[[del]]
*[[localStorage]]
*[[localStorage]]
*[[new object]]
*[[items]]
*[[keys]]

2020년 11월 2일 (월) 02:31 기준 최신판

Associative arrays
Hash
hash map
hash table
Dictionary
dict
NSDictionary
NSMutableDictionary

1 Bash[ | ]

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

for k in "${!MEMBER[@]}"; do
  echo "[$k] ${MEMBER[$k]}"
done
# [Address] Naha, Okinawa
# [ID] 102
# [Name] YONEZAWA Akinori
declare -A MEMBER
MEMBER["ID"]=102
MEMBER["Name"]="YONEZAWA Akinori"
MEMBER["Address"]="Naha, Okinawa"
declare -A MEMBER
MEMBER=(["ID"]=102)
MEMBER+=(["Name"]="YONEZAWA Akinori")
MEMBER+=(["Address"]="Naha, Okinawa")

2 C#[ | ]

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

3 Java[ | ]

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

4 JavaScript[ | ]

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

5 Objective-C[ | ]

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

6 PHP[ | ]

$member = array(
  "ID" => 102,
  "Name" => "YONEZAWA Akinori",
  "Address"=> "Naha, Okinawa"
);
$member = [
  "ID" => 102,
  "Name" => "YONEZAWA Akinori",
  "Address"=> "Naha, Okinawa"
];
$member = array();
$member['ID'] = 102;
$member['Name'] = "YONEZAWA Akinori";
$member['Address'] = "Naha, Okinawa";
$member = [];
$member['ID'] = 102;
$member['Name'] = "YONEZAWA Akinori";
$member['Address'] = "Naha, Okinawa";

7 Python[ | ]

d = dict(a=1, b=2, c=3)
print( d )
# {'b': 2, 'c': 3, 'a': 1}
member = { 'ID' : 102, 'Name' : 'YONEZAWA Akinori', 'Address' : 'Naha, Okinawa' }
from pprint import pprint
member = { }
member['ID'] = 102
member['Name'] = 'YONEZAWA Akinori'
member['Address'] = 'Naha, Okinawa'
pprint( member )
# {'Address': 'Naha, Okinawa', 'ID': 102, 'Name': 'YONEZAWA Akinori'}

8 Ruby[ | ]

string key
member = {
  "ID" => 102,
  "Name" => "YONEZAWA Akinori",
  "Address"=> "Naha, Okinawa"
}
puts member 
# {"ID"=>102, "Name"=>"YONEZAWA Akinori", "Address"=>"Naha, Okinawa"}
member = {}
member['ID'] = 102
member['Name'] = 'YONEZAWA Akinori'
member['Address'] = 'Naha, Okinawa'
puts member
# {'Address': 'Naha, Okinawa', 'ID': 102, 'Name': 'YONEZAWA Akinori'}
member = Hash.new
member['ID'] = 102
member['Name'] = 'YONEZAWA Akinori'
member['Address'] = 'Naha, Okinawa'
puts member
# {'Address': 'Naha, Okinawa', 'ID': 102, 'Name': 'YONEZAWA Akinori'}
symbol key
member = {
  ID: 102,
  Name: "YONEZAWA Akinori",
  Address: "Naha, Okinawa"
}
print member 
# {:ID=>102, :Name=>"YONEZAWA Akinori", :Address=>"Naha, Okinawa"}

9 Perl[ | ]

my %month = (
	"January" => "1월",
	"February" => "2월",
	"March" => "3월",
	"April" => "4월",
	"May" => "5월",
	"June" => "6월",
	"July" => "7월",
	"August" => "8월",
	"September" => "9월",
	"October" => "10월",
	"November" => "11월",
	"December" => "12월"
);

$month{"January"} = "일월";
$month{"March"} = "삼월";

foreach my $key (keys %month) {
	my $value = $month{$key};
	print "$key : $value\n";
}
#February : 2월
#December : 12월
#June : 6월
#July : 7월
#November : 11월
#April : 4월
#May : 5월
#January : 일월
#August : 8월
#October : 10월
#March : 삼월
#September : 9월

10 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}