| FRAMES NO FRAMES | |||||||
| |||||||
| SUMMARY: IMPORT | CONSTANT | MEMBER | ACTION | DETAIL: IMPORT | CONSTANT | MEMBER | ACTION | ||||||
dictionary<KEY,VALUE> varnameDictionaries are dynamic, and new entries can be added and existing entries deleted as desired.
// A simple stock dictionary, each stock's name is gained and
// stored from a numerical key
dictionary<integer,string> stockdict;
// A dictionary that can be used to store the number of times
// that a given event is received
dictionary<StockChoice,integer> stockCounterDict; Note that a dictionary of sequences or dictionaries is supported. For example: dictionary<integer,sequence<float>> dictOfSeq;A global variable of type dictionary is initialized by default to an empty instance of the type defined. On the other hand, a local variable must be explicitly initialized using the new operator, as follows:
dictionary<integer,string> stockdict;
stockdict := new dictionary<integer,string>; It is also possible to both declare and populate a variable of type dictionary as a single statement, regardless of the scope in which the variable is declared, as follows: dictionary<integer,string> stockdict := {1:"IBM", 2:"MSFT", 3:"ORCL"}; using {} to delimit the dictionary, a comma (,) to delimit individual entries, and a colon (:) to separate keys and values.
dictionary<string,integer> dict := new dictionary<string,integer>;
dict["A"] := 1; // insert an entry
integer a := dict["A"]; // retrieve an entry
integer b := dict["B"]; // throws an exception because "B" does not exist
| Action summary | |
|---|---|
void | add(KEY key, VALUE item)
Add an entry to the dictionary. |
boolean | static canParse(string s)
Check if the string argument can be successfully parsed as a dictionary. |
void | clear()
Set the size of the dictionary to 0, deleting all entries. |
dictionary<KEY, VALUE> | clone()
Create a deep copy of this dictionary. |
VALUE | getOr(KEY key, VALUE default)
Return the item for the specified key if it exists, or the default if it does not. |
VALUE | getOrAdd(KEY key, VALUE default)
Return the item for the specified key if it exists, or add and return a specified default if it does not. |
VALUE | getOrAddDefault(KEY key)
Return the item for the specified key if it exists, or add and return a default-initialized VALUE if not. |
VALUE | getOrDefault(KEY key)
Return the item for the specified key if it exists, or a default-initialized VALUE if it does not. |
integer | hash()
Get an integer hash representation of the underlying object. |
boolean | hasKey(KEY key)
Check whether a key exists in this dictionary. |
sequence<KEY> | keys()
Return all the keys in the dictionary. |
dictionary<KEY, VALUE> | static parse(string s)
Parse a string into a dictionary. |
void | remove(KEY key)
Remove the entry with this key. |
integer | size()
Return the size of the dictionary. |
string | toString()
Convert the dictionary to a string. |
sequence<VALUE> | values()
Return all the values in the dictionary. |
| Action detail |
|---|
void add(KEY key, VALUE item)
Add an entry to the dictionary.
boolean static canParse(string s)
Check if the string argument can be successfully parsed as a dictionary.
void clear()
Set the size of the dictionary to 0, deleting all entries.
dictionary<KEY, VALUE> clone()
Create a deep copy of this dictionary.
VALUE getOr(KEY key, VALUE default)
Return the item for the specified key if it exists, or the default if it does not.
VALUE getOrAdd(KEY key, VALUE default)
Return the item for the specified key if it exists, or add and return a specified default if it does not.
VALUE getOrAddDefault(KEY key)
Return the item for the specified key if it exists, or add and return a default-initialized VALUE if not.
VALUE getOrDefault(KEY key)
Return the item for the specified key if it exists, or a default-initialized VALUE if it does not.
integer hash()
Get an integer hash representation of the underlying object.
boolean hasKey(KEY key)
Check whether a key exists in this dictionary.
sequence<KEY> keys()
Return all the keys in the dictionary.
dictionary<KEY, VALUE> static parse(string s)
Parse a string into a dictionary.
void remove(KEY key)
Remove the entry with this key.
integer size()
Return the size of the dictionary.
string toString()
Convert the dictionary to a string.
sequence<VALUE> values()
Return all the values in the dictionary.
| FRAMES NO FRAMES | |||||||
| |||||||
| SUMMARY: IMPORT | CONSTANT | MEMBER | ACTION | DETAIL: IMPORT | CONSTANT | MEMBER | ACTION | ||||||