Friday 15 August 2014

Is there an eval() function in Java? -



Is there an eval() function in Java? -

i have string following:

string str = "4*5";

now have result of 20 using string.

i know in other languages eval() function this. how can in java?

you can utilize scriptengine class , evaluate javascript string.

scriptenginemanager manager = new scriptenginemanager(); scriptengine engine = manager.getenginebyname("js"); object result = engine.eval("4*5");

there may improve way, 1 works.

java eval

No comments:

Post a Comment