is it a Map or List?
{RF:06a838b0={alias=BX5, deviceModel=device_type.bx, deviceId=RF:06a838b0}, RF:9d4e2b70={alias=back keypad, deviceModel=device_type.keypad, ........
_type.pir, deviceId=RF:99af0330}}
It is an array with nested arrays inside. I use the simple array in my code. Example
state.preset1 = {playerNo=5, path=l5350, station=News Talk 820, type=cp, player=iHeartRadio}
in start method for the preset:
def psData = state.preset1
sendSyncCmd("/CPM?cmd=%3Cname%3EPlayById%3C/name%3E" +
"%3Cp%20type=%22str%22%20name=%22cpname%22%20val=%22${psData.player}%22/%3E" +
"%3Cp%20type=%22str%22%20name=%22mediaid%22%20val=%22${psData.path}%22/%3E")
i
I'm going through a lot of my code replacing def with the correct type eg String, Integer, Map, List and it is having significant speed improvements so what is the correct type, is it just Array,?
What's the difference between that and a map or list?
An array is indicated by [] after the data type. For example:
String[] myvar
would create a string array and
String myvar
would create a single value entity.
A map is a type of array used for cross-referencing one value for another. For example:
def colors = [red: ‘#ff0000’, green: ‘#00ff00’]
A list is a comma-separated set of elements. It is similar to an array. Example:
def numbers = [1, 2, 3]
Notice that the values of a map and list are typically defined at the instantiation of the variable as opposed to the array that has memory location allocated for the values to be stored in later.
You can get more detailed information at https://docs.groovy-lang.org.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.