Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
use std::collections::BTreeMap;
let mut x = BTreeMap::new();
x.insert("one", 1);
x.insert("two", 2);
use std::collections::HashMap;
let x: HashMap<&str, i32> = [
    ("one", 1),
    ("two", 2),
].into_iter().collect();
with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Strings.Hash;

use Ada.Containers;
declare
   package Maps is new Indefinite_Hashed_Maps (Key_Type => String,
                                               Element_Type => Integer,
                                               Hash => Ada.Strings.Hash,
                                               Equivalent_Keys => "=");
      
   use Maps;
      
   X : Map := Empty_Map;
begin
   X.Insert ("One", 1);
   X.Insert ("Two", 2);
   X.Insert ("Three", 3);
end;
#include <search.h>
ENTRY a = {"foo", "twenty"};
ENTRY b = {"bar", "three"};
if (hcreate (23)) {
    hsearch(a, ENTER);
    hsearch(b, ENTER);
}
module StringMap = Map.Make(String)

let x =
    StringMap.empty
    |> StringMap.add "one" 1
    |> StringMap.add "two" 2
    |> StringMap.add "three" 3
(def x {"One" 1
	"Two" 2
	"Three" 3})
#include <map>
std::map<const char*, int> x;
x["one"] = 1;
x["two"] = 2;
#include <unordered_map>
std::unordered_map<std::string, double> mymap = {
    {"mom", 5.4},
    {"dad", 6.1},
    {"bro", 5.9}
};
using System.Collections.Generic;
var x = new Dictionary<string, int> {
   ["year"] = 2019,
   ["month"] = 12
};
using System.Collections.Generic;
var x = new Dictionary<string, int> {
   {"year", 2019}, {"month", 12}
};
int[string] x = ["one": 1, "two": 2];
var x = {
	"one": 1,
	"two": 2
};
x = %{"one" => 1, "two" => 2}
x = %{one: 1, two: 2}
X = #{one => 1, "two" => 2.0, <<"three">> => [i, i, i]}.
x := map[string]int {"one": 1, "two": 2}
def x = ['un':1, 'dos':2, 'tres':3]
def x = [un:1, dos:2, tres:3]
import Data.Map.Strict
x = Data.Map.Strict.fromList [ ("red", "FF0000"), ("blue", "0000FF") ]

const x = new Map();
x.set("one", 1);
x.set("two", 2);
const x = {one: 1, two:2}
const x = new Map([["one",1],["two",2]]);
import java.util.Map;
import java.util.HashMap;
Map<String,Integer> x = new HashMap<>();
x.put("one", 1);
x.put("two", 2);
import static java.util.Map.entry;
import static java.util.Map.ofEntries;
import java.util.Map;
import java.util.Map.Entry;
Entry<?, ?> a = entry('a', 1),
            b = entry('b', 2),
            c = entry('c', 3);
Map<?, ?> x = ofEntries(a, b, c);
Map<?, ?> x = Map.of('a', 1, 'b', 2, 'c', 3);
import java.util.Map;
import java.util.HashMap;
final Map<String, Integer> x = new HashMap<String, Integer>() {{
    put("one", 1);
    put("two", 2);
    put("three", 3);
}};
val x = mutableMapOf<String, Int>().apply { 
    this["one"] = 1
    this["two"] = 2
}
val x = mapOf("one" to 1, "two" to 2)
val x = mutableMapOf<String, Int>()
x["one"] = 1
x["two"] = 2
(let ((table (make-hash-table)))
  (setf (gethash 'one table) 1)
  (setf	(gethash 'two table) 2))
x = {one = 1, two = 2}
NSDictionary *x=@{@"one":@1, @"two":@2};
$x = ['one' => 1, 'two' => 2];
uses fgl;
type TMap = specialize TFPGMap<String, Integer>;
var x: TMap;

begin
  x := TMap.Create;
  x['one'] := 1;
  x['two'] := 2;  
end.
my %x = ( 
    name => 'Roboticus',
    'foo bar' => 'joe'
);
x = {"one" : 1, "two" : 2}
x = {one: 1, two: 2}
val x = Map("a" -> 1, "b" -> 2, "c" -> 3)
(define x '(
    ("one" 1) 
    ("two" 2) 
    ("three" 3)))
x := Dictionary newFrom: {
	#a -> 1.
	#b -> Object new}.
Imports System.Collections.Generic
Dim x As New Dictionary(Of String, Integer)() From {
    {"one", 1},
    {"two", 2}
}

New implementation...