Search code examples
javasum

Is there any method to sum elements in JAVA?


Is there any equivalent of python's sum() in Java?


Solution

  • There's nothing built into the language. There are plenty of libraries that do things like that, though. Or write your own three-line routine. How you do it depends on how you are representing your elements (the usual suspects—for double values—being List<Double> or double[]).