concatenate two list - Java java.util

Java examples for java.util:List Compare

Description

concatenate two list

Demo Code


//package com.book2s;
import java.util.ArrayList;

import java.util.List;

public class Main {
    public static void main(String[] argv) {
        List xs = java.util.Arrays.asList("asdf", "book2s.com");
        List ys = java.util.Arrays.asList("asdf", "book2s.com");
        System.out.println(concat(xs, ys));
    }//from   w  ww .j a  va2  s  .  co  m

    public static <A> List<A> concat(List<A> xs, List<A> ys) {
        List<A> zs = new ArrayList<A>(xs.size() + ys.size());
        for (A x : xs)
            zs.add(x);
        for (A y : ys)
            zs.add(y);
        return zs;
    }
}

Related Tutorials