get Difference Of Two List - Java java.util

Java examples for java.util:List Compare

Description

get Difference Of Two List

Demo Code


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

import java.util.Iterator;
import java.util.List;

public class Main {
    public static void main(String[] argv) {
        List originList = java.util.Arrays.asList("asdf", "book2s.com");
        List targetList = java.util.Arrays.asList("asdf", "book2s.com");
        System.out.println(getDifferenceOfTwoList(originList, targetList));
    }/*www.ja v a 2s  .c o m*/

    public static List getDifferenceOfTwoList(List originList,
            List targetList) {
        List diff = new ArrayList();
        for (Iterator it = originList.iterator(); it.hasNext();) {
            Object obj = it.next();
            if (!targetList.contains(obj)) {
                diff.add(obj);
            }
        }
        return diff;
    }
}

Related Tutorials