boolean expression parser in java

You could do this with MVEL or JUEL. Both are expression language libraries, examples below are using MVEL.

Example:

System.out.println(MVEL.eval("true && ( false || ( false && true ) )"));

Prints:
false

If you literally want to use ‘T’ and ‘F’ you can do this:

Map<String, Object> context = new java.util.HashMap<String, Object>();
context.put("T", true);
context.put("F", false);
System.out.println(MVEL.eval("T && ( F || ( F && T ) )", context));

Prints:
false

Leave a Comment