1

I need to parse a math expression in Java. Currently, I'm using JEP library (2.23 free version) , which provides a parser that allows a large set of operations. However, I need to also perform operations over arrays, such as mean, sum, max, ... I had a look to the mXparser library: it provides such operations, but arrays are not currently supported. Precisely, all the values in the array have to be explicitly specified; e.g.

Expression e = new Expression("mean(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)");

Is there a similar library able to work with arrays? I'd like something like this:

Expression e = new Expression("mean(array)");

Thanks in advance

Fab
  • 1,145
  • 7
  • 20
  • 40
  • use `String expression = "mean(" + StringUtils.join(arrayObj,"','") + ")";` and then `Expression e = new Expression(expression)`. more on stringutils check http://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/StringUtils.html#join%28java.util.Iterator,%20char%29 – Ibrahim Oct 11 '16 at 14:05
  • Great! It allows overcoming the lack of array management of the mXparser library. Thank you, so much! – Fab Oct 11 '16 at 14:51
  • Possible duplicate of http://stackoverflow.com/q/1978933/1661938 – Frederic Klein Oct 12 '16 at 08:12

0 Answers0