ScriptEngine: get(String key)
import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class Main { public static void main(String args[]) { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("javascript"); try { engine.put("name", "abcde"); engine.eval("var output = '';for (i = 0; i <= name.length; i++) {" + " output = name.charAt(i)+'-' + output" + "}"); String name = (String) engine.get("output"); System.out.println(name); } catch (ScriptException e) { System.err.println(e); } } }
1. | ScriptEngine: eval(String script) | ||
2. | ScriptEngine: eval(Reader reader) | ||
3. | ScriptEngine: getBindings(int scope) | ||
4. | ScriptEngine: put(String key, Object value) |