• 0

[Java] Sum of array elements?


Question

Is there a java function that sums up all of the elements of an array? because i don't want to have to write out a loop to count it or do array[1] + array[2] etc......

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

AFAIK there is none, and it would be normal because the java array is designed to hold any kind of object, not just integers or types that can be summed together. If you really need a sum() method for your arrays, just create your own Array class by extending the Java Array class.

Link to comment
Share on other sites

  • 0

Or use C# Framework 3.5 and just use partial methods to extend the actual arraylist class! (This saves you referencing a user defined class everywhere) C# FTW! ;)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.