Skip to content

Instantly share code, notes, and snippets.

@evnm
Created September 24, 2011 05:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evnm/1239014 to your computer and use it in GitHub Desktop.
Save evnm/1239014 to your computer and use it in GitHub Desktop.
Java vs Scala array sum example
// Java.
int sum = 0;
for (int i = 0; i < arr.length; i++) {
sum += arr[i];
}
System.out.println(sum);
// Scala (ignoring arr.sum).
println(arr reduceLeft { _ + _ })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment