How to string array syntax?

I need string array with 10 elments, and cycle to access each element.
I didnt found examples in wiki.

Thanx for help.

At least according to Designer’s syntax highlighting it doesn’t appear that openHAB’s rules support arrays so you will need to use a List.

val myList = newArrayList('One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten')

Looping will depend on what you want to do. You can do a forEach:

myList.forEach[ str |
    // do stuff

or an Iterator:

val iterator = myList.iterator
while(iterator.hasNext) {
    val str =
    // do stuff

Needing to create an array like this and iterate over them is a rare need which is why you didn’t find an example in the wiki.



How to create fixed size array?
I use this code, but it ugly:

var OledLines = newArrayList()

 OledLines.set(20, "Test")

I use it to post messages to OLED display in particular line.

The Rule’s DSL doesn’t have good support for arrays. ArrayList isn’t really an array, its a collection and it is not fixed sized.

You can try to see if one the following with work:

var OledLines = newArrayList(32)

var List<String> OledLines = new ArrayList(32)

Note that you will have to import both java.util.List and java.util.ArrayList for that second example to work.

Another cheezy hack could be:

var OledLines = " , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,".split(',')