Questions tagged [key-value]

A key-value pair is a set of two linked data items: a key which uniquely identifies some item of data, and the value, which is either the data that is identified or a pointer to the location of that data. Key-value pairs are frequently used in lookup tables, hash tables and configuration files.

A key-value pair is a set of two linked data items: a key which uniquely identifies some item of data, and the value, which is either the data that is identified or a pointer to the location of that data. Key-value pairs are frequently used in lookup tables, hash tables and configuration files.

http://searchenterprisedesktop.techtarget.com/definition/key-value-pair

A collection of key-value pairs is called an associative array.

The concept of key value pairs is applied in modern NoSQL databases for representing a storage mechanism. Key-Value is also a way to assign attributes and values to NSObject based instances in Cocoa framework (Related: Objective-C).

3201 questions
599
votes
28 answers

How to remove elements from a generic list while iterating over it?

I am looking for a better pattern for working with a list of elements which each need processed and then depending on the outcome are removed from the list. You can't use .Remove(element) inside a foreach (var element in X) (because it results in…
InvertedAcceleration
  • 10,695
  • 9
  • 46
  • 71
596
votes
8 answers

Java Class that implements Map and keeps insertion order?

I'm looking for a class in java that has key-value association, but without using hashes. Here is what I'm currently doing: Add values to a Hashtable. Get an iterator for the Hashtable.entrySet(). Iterate through all values and: Get a Map.Entry…
Shane
  • 6,045
  • 3
  • 19
  • 7
482
votes
8 answers

The default for KeyValuePair

I have an object of the type IEnumerable> keyValueList, I am using var getResult= keyValueList.SingleOrDefault(); if(getResult==/*default */) { } else { } How can I check whether getResult is the default, in case I can't…
Graviton
  • 81,782
  • 146
  • 424
  • 602
438
votes
5 answers

How to iterate over associative arrays in Bash

Based on an associative array in a Bash script, I need to iterate over it to get the key and value. #!/bin/bash declare -A array array[foo]=bar array[bar]=foo I actually don't understand how to get the key while using a for-in loop.
pex
  • 7,351
  • 4
  • 32
  • 41
435
votes
17 answers

How to create a dictionary and add key value pairs dynamically in JavaScript

From post: Sending a JSON array to be received as a Dictionary, I'm trying to do this same thing as that post. The only issue is that I don't know what the keys and the values are upfront. So I need to be able to dynamically add the…
KenEucker
  • 4,932
  • 5
  • 22
  • 28
405
votes
11 answers

Java - How to create new Entry (key, value)

I'd like to create new item that similarly to Util.Map.Entry that will contain the structure key, value. The problem is that I can't instantiate a Map.Entry because it's an interface. Does anyone know how to create a new generic key/value object…
Spiderman
  • 9,602
  • 13
  • 48
  • 56
284
votes
7 answers

for each loop in Objective-C for accessing NSMutable dictionary

I am finding some difficulty in accessing mutable dictionary keys and values in Objective-C. Suppose I have this: NSMutableDictionary *xyz=[[NSMutableDictionary alloc] init]; I can set keys and values. Now, I just want to access each key and value,…
sagarkothari
  • 24,520
  • 50
  • 165
  • 235
283
votes
4 answers

How do you create a dictionary in Java?

I am trying to implement a dictionary (as in the physical book). I have a list of words and their meanings. What data structure / type does Java provide to store a list of words and their meanings as key/value pairs. How, given a key, can I find…
user1849819
  • 2,889
  • 2
  • 13
  • 3
263
votes
12 answers

What is the difference between a map and a dictionary?

I know a map is a data structure that maps keys to values. Isn't a dictionary the same? What is the difference between a map and a dictionary1? 1. I am not asking for how they are defined in language X or Y (which seems to be what generally people…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
257
votes
10 answers

A KeyValuePair in Java

I'm looking for a KeyValuePair class in Java. Since java.util heavily uses interfaces there is no concrete implementation provided, only the Map.Entry interface. Is there some canonical implementation I can import? It is one of those "plumbers…
maayank
  • 4,200
  • 2
  • 24
  • 23
256
votes
15 answers

How to extract all values from a dictionary in Python?

I have a dictionary d = {1:-0.3246, 2:-0.9185, 3:-3985, ...}. How do I extract all of the values of d into a list l?
Naveen C.
  • 3,185
  • 5
  • 21
  • 12
178
votes
25 answers

Swap key with value in object

I have an extremely large JSON object structured like this: {A : 1, B : 2, C : 3, D : 4} I need a function that can swap the values with keys in my object and I don't know how to do it. I would need an output like this: {1 : A, 2 : B, 3 : C, 4 :…
C1D
  • 3,034
  • 2
  • 21
  • 20
172
votes
7 answers

append multiple values for one key in a dictionary

I am new to python and I have a list of years and values for each year. What I want to do is check if the year already exists in a dictionary and if it does, append the value to that list of values for the specific key. So for instance, I have a…
anon
  • 1,733
  • 2
  • 11
  • 6
161
votes
3 answers

How to loop through key/value object in Javascript?

var user = {}; now I want to create a setUsers() method that takes a key/value pair object and initializes the user variable. setUsers = function(data) { // loop and init user } where data is like: 234: "john", 23421: "smith", ....
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
142
votes
10 answers

Entity Attribute Value Database vs. strict Relational Model Ecommerce

It is safe to say that the EAV/CR database model is bad. That said, Question: What database model, technique, or pattern should be used to deal with "classes" of attributes describing e-commerce products which can be changed at run time? In a…
Zachary Scott
  • 20,968
  • 35
  • 123
  • 205
1
2 3
99 100