key-value

Can the key in a Java property include a blank character?

独自空忆成欢 提交于 2019-11-28 20:08:25
We are getting properties (that we can not influence) out of a database and want to access them by a key/value mapping. We are facing the problem that one of the property keys includes a blank character. foo bar = barefoot This is - correctly - interpreted as follows key: foo value: bar = barefoot Is there a way to include the blank in the key so that it's not interpreted as the delimiter? I guess this behaviour is just like intended, but I thought I could give it a try here. As it seems the delimiter should be = , not space. Hence - keyValuePair.split("=") should do. If you are loading this

how to prevent adding duplicate keys to a javascript array

非 Y 不嫁゛ 提交于 2019-11-28 18:45:54
问题 I found a lot of related questions with answers talking about for...in loops and using hasOwnProperty but nothing I do works properly. All I want to do is check whether or not a key exists in an array and if not, add it. I start with an empty array then add keys as the page is scrubbed with jQuery. Initially, I hoped that something simple like the following would work: (using generic names) if (!array[key]) array[key] = value; No go. Followed it up with: for (var in array) { if (!array

How to search if dictionary value contains certain string with Python

时光怂恿深爱的人放手 提交于 2019-11-28 17:59:05
I have a dictionary with key-value pair. My value contains strings. How can I search if a specific string exists in the dictionary and return the key that correspond to the key that contains the value. Let's say I want to search if the string 'Mary' exists in the dictionary value and get the key that contains it. This is what I tried but obviously it doesn't work that way. #Just an example how the dictionary may look like myDict = {'age': ['12'], 'address': ['34 Main Street, 212 First Avenue'], 'firstName': ['Alan', 'Mary-Ann'], 'lastName': ['Stone', 'Lee']} #Checking if string 'Mary' exists

How to loop through key/value object in Javascript? [duplicate]

瘦欲@ 提交于 2019-11-28 17:20:40
This question already has an answer here: For..In loops in JavaScript - key value pairs 15 answers 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", .... Beware of properties inherited from the object's prototype (which could happen if you're including any libraries on your page, such as older versions of Prototype). You can check for this by using the object's hasOwnProperty() method. This is generally a good idea when

iPhone - How to detect if a key exists in NSUserDefaults standardUserDefaults

倖福魔咒の 提交于 2019-11-28 16:44:52
问题 Using NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; , I use calls like BOOL boolFromPrefs = [defaults boolForKey:@"theBoolKey"]; To get a saved BOOL value. If the key is not found, NO is returned (default behaviour of boolForKey). But... NO can be a saved setting. Same thing for intForKey So how can I test if a key exists before trying to get its value ? 回答1: Do it the right way and register default values. NSDictionary *userDefaultsDefaults = @{ @"SomeKey": @NO, @

Go map of functions

孤人 提交于 2019-11-28 16:39:46
问题 I have Go program that has a function defined. I also have a map that should have a key for each function. How can I do that? I have tried this, but this doesn't work. func a(param string) { } m := map[string] func { 'a_func': a, } for key, value := range m { if key == 'a_func' { value(param) } } 回答1: Are you trying to do something like this? I've revised the example to use varying types and numbers of function parameters. package main import "fmt" func f(p string) { fmt.Println("function f

Reliable and efficient key--value database for Linux? [closed]

独自空忆成欢 提交于 2019-11-28 15:43:49
I need a fast, reliable and memory-efficient key--value database for Linux. My keys are about 128 bytes, and the maximum value size can be 128K or 256K. The database subsystem shouldn't use more than about 1 MB of RAM. The total database size is 20G (!), but only a small random fraction of the data is accessed at a time. If necessary, I can move some data blobs out of the database (to regular files), so the size gets down to 2 GB maximum. The database must survive a system crash without any loss in recently unmodified data. I'll have about 100 times more reads than writes. It is a plus if it

Storing Directory Hierarchy in a Key-Value Data store

心不动则不痛 提交于 2019-11-28 15:39:58
What is a clean/efficient method for storing the directory Hierarchy/tree in a Key-Value database (in my case MongoDB but any of them)? For example a tree structure - Cars + Audi + BMW - M5 + Ford - Color + Red - Apple - Cherry + Purple - Funny The method I am using now, each object links to it's parent { dir: "red" parent-dir: "color" } This makes it very efficient/fast to insert and reorder any aspect of the tree (for example if I want to move Red and all it's children to the Cars directory). But this method sucks when I want to all subdirectories and their children for a given directory

A KeyValuePair in Java

依然范特西╮ 提交于 2019-11-28 15:31:53
问题 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 programming" classes I hate to implement 100x times. 回答1: The documentation AbstractMap.SimpleEntry is generic and can be useful. 回答2: Android programmers could use BasicNameValuePair Update: BasicNameValuePair is now deprecated (API 22). Use Pair

How to push both key and value into an Array in Jquery

若如初见. 提交于 2019-11-28 15:30:27
I am reading RSS feed and pushing both Title and Link into an Array in Jquery . What i did is var arr = []; $.getJSON("displayjson.php",function(data){ $.each(data.news, function(i,news){ var title = news.title; var link = news.link; arr.push({title : link}); }); }); And i am reading that array again using $('#show').click(function(){ $.each(arr, function(index, value){ alert( index +' : '+value); }); }); But it Giving me Output as 1:[Object Object] 2:[Object Object] 3:[Object Object] like this ... How i can get both tile and link as a pair ( title as key and link as value ) There are no keys