Painless script arrays

Hello,

Is there a way to easily create and empty string array in Painless script, than add a string to it if it doesn't already exist in the array. I can't seem to find proper examples of arrays for Painless script anywhere.
Thanks!

Painless is mostly Java, so you can use the same logic and the majority of the methods, a basic example will be:

String[] myStrings = new String[4];
boolean exist = false;

myStrings[0] = "Hello";
myStrings[1] = "World";
myStrings[2] = "From";
myStrings[3] = "Java";

String textInput = "Hello";

for (int i = 0; i < myStrings.length; ++i) {
    if (textInput.equals(myStrings[i])) {
        exist = true;
    }
}

return exist;

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.