Java List Value Add All addAll(List fromList, List toList)

Here you can find the source of addAll(List fromList, List toList)

Description

add All

License

Apache License

Declaration

public static void addAll(List fromList, List toList) 

Method Source Code

//package com.java2s;
/**//from w ww . j av a2s  .c om
 * Copyright 2016 William Van Woensel
    
   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.
 * 
 * 
 * @author wvw
 * 
 */

import java.util.List;

public class Main {
    public static void addAll(List fromList, List toList) {
        addAll(fromList, toList, false);
    }

    public static void addAll(List fromList, List toList, boolean checkDupl) {
        for (int i = 0; i < fromList.size(); i++) {
            Object obj = fromList.get(i);
            if (!checkDupl || !contains(toList, obj))
                toList.add(obj);
        }
    }

    public static boolean contains(List lsttor, Object val) {
        for (int i = 0; i < lsttor.size(); i++)
            if (lsttor.get(i).equals(val))
                return true;

        return false;
    }

    public static boolean equals(List lst1, List lst2) {
        if (lst1.size() != lst2.size())
            return false;

        for (Object obj1 : lst1) {

            boolean match = false;
            for (Object obj2 : lst2) {

                if (obj1.equals(obj2)) {
                    match = true;

                    break;
                }
            }

            if (!match)
                return false;
        }

        return true;
    }
}

Related

  1. addAll(final List list, final E... values)
  2. addAll(final List firstList, final List secondList)
  3. addAll(final List list, final T... elements)
  4. addAll(int index, List list, T... array)
  5. addAll(List dest, List src)
  6. addAll(List list, E[] elements)
  7. addAll(List list, String[] array)
  8. addAll(List list, T... array)
  9. addAll(List src, T... args)