Constructors
Map Map()
Creates an empty map.Map Map(String value)
Pass aString containing key-value pairs separated by “\n”:
“key=value\nkey=value\nkey=value,…”
Don’t add space between \n and the 1st character of the key!
Adding elements to maps
Map insert(String key, String value)
insert() adds a new key-value pair to the map.
Accessing elements in maps
Bool exists(String key)
exists() checks if the map contains the given key.
Integer size()
size() counts the elements in the map and returns that number.
String get(String key)
Returns the value for the given key.getKey() and getVal() also retrieve data from the map. These methods depend on the internal iterator of the map and are described in the Looping section.
String getWithFallback(String key, String fallback)
Returns the fallback value if key does not exist.Updating elements
When working with numeric strings, you can increment values stored in the map. The increment can be given as either Integer or Float. In both cases, you provide the key to look up the element and the value to add to the currently stored value.Void increaseValueForKey(String key, Integer value)
Void increaseValueForKey(String key, Float value)
Removing elements
You can remove either a specific element identified by its key, or you can remove all elements.Void remove(String key)
Removes the element with the given key.Void clear()
Removes all elements from the map.Looping maps
Looping (or iterating) maps is similar to looping an array. However, where you would declare and update the Integer iterator for the array index, Maps have a built-in iterator that you position.insert() resets the map iterator when called.Bool eof()
Returns true if the map iterator has moved past the end of the map, otherwise false.That
eof() returns true is not the same as the map is empty. It can be, but it doesn’t have to be. Use size() to check if the map is truly empty.Bool first()
Rewinds the internal iterator to the 1st element.first() returns false if the map is empty.
Bool next()
Moves the map iterator to next position.next() returns false if eof().