Java - Write code to add element from one List to another list

Requirements

Write code to add element from one List to another list

Demo

//package com.book2s;

import java.util.List;

public class Main {
    public static void main(String[] argv) {
        List toList = java.util.Arrays.asList("asdf", "book2s.com");
        List fromList = java.util.Arrays.asList("asdf", "book2s.com");
        add(toList, fromList);//from w ww.  jav a 2s .c om
    }

    public static <T> void add(final List<T> toList, final List<T> fromList) {

        if (toList == null || fromList == null) {
            return;
        }

        for (T t : fromList) {
            if (!toList.contains(t)) {
                toList.add(t);
            }
        }
    }
}

Related Exercise