1.数组合并同时删除相同的元素2.删除数组某些元素

/**
 * 并两个字符串去除重(字符串必,分割)
 *
 * @param aStr
 * @param bStr
 * @return
 */
private String mergeString(String aStr, String bStr) {
    if (aStr == null || bStr == null) {
        return null;
    }
    String[] aArr = aStr.split(",");
    String[] bArr = bStr.split(",");
    Set set = Sets.newHashSet();
    set.addAll(Arrays.asList(aArr));
    set.addAll(Arrays.asList(bArr));
    return Arrays.toString(set.toArray());
}

/**
 * targetStrcutStr中的(字符串必,分割)
 *
 * @param targetStr
 * @param cutStr
 * @return
 */
private String cutString(String targetStr, String cutStr) {
    if (targetStr == null || cutStr == null) {
        return null;
    }
    String[] tarArr = targetStr.split(",");
    String[] cutArr = cutStr.split(",");
    Set set = Sets.newHashSet();
    set.addAll(Arrays.asList(tarArr));
    set.removeAll(Arrays.asList(cutArr));
    return Arrays.toString(set.toArray());
}

你可能感兴趣的:(java,工具类,数组,工具类)