Q:

how can I use string value as an argument?

for example:  
>String str="index==1";  
>int index=1;  
>if(str)  
>       System.out.println("1");  

what I mean is that the 'if' will use the value of "str" as an argument, and print "1".
I tryed to look for an answer and I didn't find
thank you very much!!  

A:

Java is not able to do that kind of "eval"-functions, but there is a way to use javascript in java to return the result of an "eval" with "ScriptEngineManager":
  import javax.script.*;

  String str="index==1";
  int index = 1;

  try {

    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("js");
    engine.put("index", index); //set  index as variable in js
    engine.put("str", str);//set str as variable in js

    Boolean result = (Boolean) engine.eval("result = eval(str)");  //eval function
    System.out.println("=>" + result);  //boolean as result
    if(result) System.out.println("1");

  } catch (Exception e){e.printStackTrace();}

