Java examples for java.util:List Element
Remove repeat elements in origin List by target List.
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { public static void main(String[] argv) { List origin = java.util.Arrays.asList("asdf", "java2s.com"); List target = java.util.Arrays.asList("asdf", "java2s.com"); System.out.println(removeRepeatElements(origin, target)); }/*from w w w. j a v a 2s. c om*/ /** * Remove repeat elements in origin List by target List. */ public static <T> List<T> removeRepeatElements(List<T> origin, List<T> target) { if (origin == null || target == null) { return target; } List<T> temp = new ArrayList<T>(); if (!isEmpty(origin)) { for (T object : target) { if (!origin.contains(object)) { temp.add(object); } } return temp; } return target; } /** * Check if the specified collection is empty(null or size is zero)? */ public static boolean isEmpty(Collection<?> collection) { if (size(collection) == 0) { return true; } return false; } /** * Get the size of specified collection. */ public static int size(Collection<?> collection) { if (collection == null) { return 0; } return collection.size(); } }