java collection 集合并操作

/**
*
* @description:实现将传入的两个集合进行并,交,联集,差操作
*
* @author jackWu
* Feb 5, 2007
*/

package com.gzsdx.itsm.common.util;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;

import com.gzsdx.itsm.common.listener.Manager;
import com.gzsdx.itsm.common.log.LogWriter;

public class CollectionPower ...{
/** *//**
* @class description: Feb 5, 2007
*/
private static final LogWriter log = Manager.log;
/** *//**
* @author jackWu
* @description:实现并操作
* Feb 5, 2007
* @param arrayA
* @param arrayB
* @return
*/
public String collectionUnion(String[] arrayA, String[] arrayB) ...{
String arrayC = "";
try ...{
List a = Arrays.asList(arrayA);
List b = Arrays.asList(arrayB);
Collection union = CollectionUtils.union(a, b);
arrayC=union.toArray().toString();
} catch (Exception ex) ...{
log.info("集合并操作失败!info===============", ex.getMessage());
}
return arrayC;
}
/** *//**
* @author jackWu
* @description:实现交操作
* Feb 5, 2007
* @param arrayA
* @param arrayB
* @return
*/
public String collectionIntersection(String[] arrayA, String[] arrayB) ...{
String arrayC = "";
try ...{
List a = Arrays.asList(arrayA);
List b = Arrays.asList(arrayB);
Collection intersection = CollectionUtils.intersection(a, b);
arrayC=intersection.toArray().toString();
} catch (Exception ex) ...{
log.info("集合并操作失败!info===============", ex.getMessage());
}
return arrayC;
}
/** *//**
* @author jackWu
* @description:实现联集操作
* Feb 5, 2007
* @param arrayA
* @param arrayB
* @return
*/
public String collectionDisjunction(String[] arrayA, String[] arrayB) ...{
String arrayC = "";
try ...{
List a = Arrays.asList(arrayA);
List b = Arrays.asList(arrayB);
Collection disjunction = CollectionUtils.disjunction(a, b);
arrayC=disjunction.toArray().toString();
} catch (Exception ex) ...{
log.info("集合并操作失败!info===============", ex.getMessage());
}
return arrayC;
}
/** *//**
* @author jackWu
* @description:实现差操作
* Feb 5, 2007
* @param arrayA
* @param arrayB
* @return
*/
public String collectionSubtract(String[] arrayA, String[] arrayB) ...{
String arrayC = "";
try ...{
List a = Arrays.asList(arrayA);
List b = Arrays.asList(arrayB);
Collection subtract = CollectionUtils.subtract(a, b);
arrayC=subtract.toArray().toString();
} catch (Exception ex) ...{
log.info("集合并操作失败!info===============", ex.getMessage());
}
return arrayC;
}
}

你可能感兴趣的:(JAVA,随笔)