Java List Difference diff(List doublesA, List doublesB)

Here you can find the source of diff(List doublesA, List doublesB)

Description

returns a list with the values difference values doublesA-doublesB

License

Open Source License

Parameter

Parameter Description
doublesA the values from which to subtract
doublesB the values which shall be subtracted

Return

a list of differences

Declaration

public static List<Double> diff(List<Double> doublesA, List<Double> doublesB) 

Method Source Code

//package com.java2s;
/*******************************************************************************
*
* This file is part of JMad./* w ww .ja  v a  2s .  c  o m*/
* 
* Copyright (c) 2008-2011, CERN. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 
******************************************************************************/

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**
     * returns a list with the values difference values doublesA-doublesB
     * 
     * @param doublesA the values from which to subtract
     * @param doublesB the values which shall be subtracted
     * @return a list of differences
     */
    public static List<Double> diff(List<Double> doublesA, List<Double> doublesB) {
        if (doublesA.size() != doublesB.size()) {
            throw new IllegalArgumentException("The two lists must be of same size!");
        }
        List<Double> diff = new ArrayList<Double>(doublesA.size());
        for (int i = 0; i < doublesA.size(); i++) {
            diff.add(doublesA.get(i) - doublesB.get(i));
        }
        return diff;
    }
}

Related

  1. diff(List ls, List ls2)
  2. diffAsSet(Collection list1, Collection list2)
  3. difference(final List minuend, final List subtrahend)
  4. difference(final List list1, final List list2)
  5. difference(final String[] list1, final String[] list2)