CollectionUtils实现两个list取得交集

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.collections.CollectionUtils;



public class hello {


	public static void main(String[] args) {
		File backdir=new File("d:\\tar\\test\\2500271331_PBL-WH-1-331_20091216_fc_access.log");
		List<String> lognames=new ArrayList<String>();
		List<String> kk=new ArrayList<String>();
		try {
			
			
			InputStream is = new FileInputStream(backdir);
			
			BufferedReader reader = new BufferedReader(new InputStreamReader(is));
			
			String line;
			
			while ((line = reader.readLine()) != null) {
				
				lognames.add(line);
				
			}
			reader.close();
			is.close();
			
			
			Set set=new HashSet();
			set.addAll(lognames);
			kk=(List<String>) CollectionUtils.disjunction(lognames, set);
			
			System.out.println(lognames.size()+":"+set.size());
			
			for(int i=0;i<kk.size();i++){
			
				System.out.println(kk.get(i));
				
			}
			
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

 

你可能感兴趣的:(java,apache,Access)