Associative array/Creation: Difference between revisions
m
→{{header|Ecstasy}}
Line 2,809:
<syntaxhighlight lang="java">Int? mightBeNull = map["foo"];
Int neverNull = map.getOrDefault("foo", 0);
if (Int n := map.get("foo")) {
// if "foo" is in the map, then the variable "n" is set to its value
} else {▼
▲else
// if "foo" is not in the map, then the variable "n" is not defined
Iterate over keys:
<syntaxhighlight lang="java">for (String key : map) {
// the variable "key" is defined here
Iterate over values:
<syntaxhighlight lang="java">for (Int value : map.values) {
// the variable "value" is defined here
Iterate over key, value pairs:
<syntaxhighlight lang="java">for ((String key, Int value) : map) {
// the variables "key" and "value" are defined here
=={{header|Elena}}==
|