Here you can find the source of subtractFloatLists(List
Parameter | Description |
---|---|
listA | the list a |
listB | the list b |
public static List<Float> subtractFloatLists(List<Float> listA, List<Float> listB)
//package com.java2s; /*//www . java 2s . c o m Copyright 2014 Array-Utilities 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.Collection; import java.util.List; public class Main { /** * Subtract float lists. * * @param listA * the list a * @param listB * the list b * @return the list */ public static List<Float> subtractFloatLists(List<Float> listA, List<Float> listB) { // ListA empty & ListB has values if (isEmpty(listA) && !isEmpty(listB)) { return listB; } // ListA has values & ListB is empty if (!isEmpty(listA) && isEmpty(listB)) { return listA; } // Both List are empty if (isEmpty(listA) && isEmpty(listB)) { return new ArrayList<Float>(); } // [1,2,3,4,5] // [3,4,5,6,7,8,9] ArrayList<Float> list = new ArrayList<Float>(); int i = 0; int j = 0; while (i < listA.size() && j < listB.size()) { list.add(listA.get(i) - listB.get(j)); i++; j++; } while (i < listA.size()) { list.add(listA.get(i)); i++; } while (j < listB.size()) { list.add(listB.get(j)); j++; } System.out.println("list is " + list); return list; } /** * Checks if is empty. * * @param <E> * the element type * @param collection * the collection * @return true, if is empty */ public static <E> boolean isEmpty(Collection<? super E> collection) { if ((collection.size() == 0) || (collection == null)) return true; return false; } }