0

I followed the answer to this SO post to write my own script. However, I do not understand how to convert from GStringImpl to String[]. How do I do that?

Thanks

public class TestGroovy {
    public static void main(String[] args) {
        Binding binding = new Binding();
        GroovyShell shell = new GroovyShell(binding);
        binding.setVariable("b", "a|b|c");
        GStringImpl value = (GStringImpl) shell.evaluate("return \"${b.split('|')}\";");// return "b.split('|')";}
        System.out.println(value);
    }
}

This prints

[a, |, b, |, c]

1 Answer 1

0

I rewrote my code as follows. I use properties instead

public static void main(String[] args) {
    Binding binding = new Binding();
    GroovyShell shell = new GroovyShell(binding);
    binding.setProperty("b", "a|b|c");
    shell.evaluate("result = b.tokenize('|');");// return "b.split('|')";}
    List<String> property = (List<String>) shell.getProperty("result");
    System.out.println(property);
    for (String s : property) {
        System.out.println(s);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.