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).

2603 questions
515
votes
9 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
  • 5,235
  • 3
  • 17
  • 7
503
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
  • 9,567
  • 9
  • 42
  • 69
422
votes
7 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
  • 76,900
  • 138
  • 399
  • 575
383
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
  • 6,731
  • 4
  • 30
  • 41
378
votes
16 answers

How to create dictionary and add key–value pairs dynamically?

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,335
  • 5
  • 20
  • 26
324
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
  • 8,124
  • 13
  • 44
  • 56
279
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,…
249
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,549
  • 2
  • 11
  • 3
245
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,050
  • 2
  • 21
  • 23
221
votes
11 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
  • 90,453
  • 117
  • 313
  • 521
155
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,563
  • 2
  • 10
  • 6
141
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
  • 236,778
  • 296
  • 715
  • 1,125
136
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,070
  • 32
  • 114
  • 195
128
votes
20 answers

Swap key with value JSON

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
  • 2,516
  • 2
  • 17
  • 19
108
votes
3 answers

What's the purpose of Kafka's key/value pair-based messaging?

All of the examples of Kafka | producers show the ProducerRecord's key/value pair as not only being the same type (all examples show ), but the same value. For example: producer.send(new ProducerRecord("someTopic",…
smeeb
  • 22,487
  • 41
  • 197
  • 389
1
2 3
99 100