对两个LIST对行比对,筛选

 

对两个LIST对行比对,筛选

以下两种方法比对中会发现用情况      (单位 ns)

     CollectionUtils    ListUtils

52354             811485

49659       790698

 

package com.collection;

import java.util.*;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.ListUtils;

public class ListFilter {

	public static void main(String[] args) {
		List l1 = new ArrayList();
		List l2 = new ArrayList();
		l1.add(1);
		l1.add(2);
		l1.add(3);
		l1.add(5);

		l2.add(4);
		l2.add(5);

		Collection s1 = CollectionUtils.union(l1, l2);
		Long start = System.nanoTime();
		Collection s2 = CollectionUtils.subtract(l1, l2);
		System.out.println(System.nanoTime() - start);
		
		Long start1 = System.nanoTime();
		List ls = ListUtils.subtract(l1, l2);
		System.out.println(System.nanoTime() - start1);
		
		Collection s3 = CollectionUtils.intersection(l1, l2);
		Collection s4 = CollectionUtils.disjunction(l1, l2);
		System.out.println(s4);
		System.out.println(s1);
		System.out.println(s2);
		System.out.println(s3);

	}

}
 

你可能感兴趣的:(list)