Skip to content

Instantly share code, notes, and snippets.

@cobratbq
Created April 29, 2016 19:55
Show Gist options
  • Save cobratbq/599eed66421ed9cfff3bb26c5d061b07 to your computer and use it in GitHub Desktop.
Save cobratbq/599eed66421ed9cfff3bb26c5d061b07 to your computer and use it in GitHub Desktop.
More flexible implementation of summing-method
public class Test {
public static void main(String[] args) {
final ArrayList<Double> list = new ArrayList<>();
list.add(1.3);
list.add(1.4);
list.add(1.7);
list.add(2.3);
flexibleSum(list);
}
public static void flexibleSum(final Iterable<Double> values) {
double sum = 0;
for (final double d : values) {
sum += d;
}
System.out.println(Double.toString(sum));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment