How to find the sum of the elements of an Int List in Scala

Hey there!

Welcome to ClearUrDoubt.com.

In this post, we will look at a Scala program to find the sum of the elements of an Int List.

We can achieve this using foldLeft or reduceLeft methods.

  • foldLeft() method accepts an initial value and a function to determine how to return the value.
  • reduceLeft() method accepts only a function to determine how to return the value.

Let’s look at the program:

Output:

Happy learning.

Please leave a reply in case of any queries.

Leave a Reply

Your email address will not be published. Required fields are marked *