Skip to content
Related Articles
Open in App
Not now

Related Articles

DoubleSummaryStatistics combine() method in Java with Examples

Improve Article
Save Article
  • Last Updated : 28 Jun, 2019
Improve Article
Save Article

The combine() method of DoubleSummaryStatistics class in Java is used to combine the given other DoubleSummaryStatistics to this DoubleSummaryStatistics.


public void combine(DoubleSummaryStatistics 

Parameter: This method accepts otherDoubleSummaryStatistics as parameter that is to be combined into this DoubleSummaryStatistics.

Return Value: This method do not returns anything.

Exception: This method throws NullPointerException if otherDoubleSummaryStatistics is null.


// Java program to demonstrate
// the above method
import java.util.*;
public class DoubleSummaryStatisticsDemo {
    public static void main(String[] args)
        DoubleSummaryStatistics doubleSummaryStatistics
            = new DoubleSummaryStatistics();
        List<Double> list = new LinkedList<>();
        Iterator<Double> iterator = list.listIterator();
        while (iterator.hasNext()) {
            // Add the doubles to the
            // DoubleSummaryStatistics object
        System.out.println("First DdoubleSummaryStatistics: "
                           + doubleSummaryStatistics
        DoubleSummaryStatistics otherDoubleSummaryStatistics
            = new DoubleSummaryStatistics();
        List<Double> list1 = new LinkedList<>();
        Iterator<Double> iterator1 = list1.listIterator();
        while (iterator1.hasNext()) {
            // Add the doubles to the
            // DoubleSummaryStatistics object
        System.out.println("Second DdoubleSummaryStatistics: "
                           + otherDoubleSummaryStatistics
        System.out.println("Combining both DdoubleSummaryStatistics"
                           + " using combine() ");
        System.out.println("Combined DdoubleSummaryStatistics: "
                           + doubleSummaryStatistics.toString());


First DdoubleSummaryStatistics:
DoubleSummaryStatistics{count=5, sum=669.476700, min=45.600000, average=133.895340, max=243.500000}
Second DdoubleSummaryStatistics:
DoubleSummaryStatistics{count=5, sum=104013.477000, min=0.000000, average=20802.695400, max=45664.700000}

Combining both DdoubleSummaryStatistics using combine()

Combined DdoubleSummaryStatistics:
DoubleSummaryStatistics{count=10, sum=104682.953700, min=0.000000, average=10468.295370, max=45664.700000}


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!