Here you can find the source of mergeList(List
public static Object mergeList(List<Object> list)
//package com.java2s; /**// w w w .jav a2s .c o m * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.Collection; import java.util.List; import java.util.Set; public class Main { public static Object mergeList(List<Object> list) { Object ret = null; for (Object value : list) { ret = add(ret, value); } return ret; } @SuppressWarnings("rawtypes") public static List<Object> mergeList(List<Object> result, Object add) { if (add instanceof Collection) { for (Object o : (Collection) add) { result.add(o); } } else if (add instanceof Set) { for (Object o : (Collection) add) { result.add(o); } } else { result.add(add); } return result; } public static Object add(Object oldValue, Object newValue) { if (oldValue == null) { return newValue; } if (oldValue instanceof Long) { if (newValue == null) { return (Long) oldValue; } else { return (Long) oldValue + Long.valueOf(String.valueOf(newValue)); } } else if (oldValue instanceof Integer) { if (newValue == null) { return (Integer) oldValue; } else { return (Integer) oldValue + Integer.valueOf(String.valueOf(newValue)); } } else if (oldValue instanceof Double) { if (newValue == null) { return (Double) oldValue; } else { return (Double) oldValue + Double.valueOf(String.valueOf(newValue)); } } else if (oldValue instanceof Float) { if (newValue == null) { return (Float) oldValue; } else { return (Float) oldValue + Float.valueOf(String.valueOf(newValue)); } } else { return null; } } }