我有一个String[]acctitleIdArray 数组,里面为[1,2,3,4],还有一个List limitSubList,里面为[1,3,7,8]
,问怎么遍历出acctitleIdArray在limitSubList里的值,和不在limitSubList里的值。把这两个结果集分别放到2个字符串中,字符串中的字符用,隔开。
,问怎么遍历出acctitleIdArray在limitSubList里的值,和不在limitSubList里的值。把这两个结果集分别放到2个字符串中,字符串中的字符用,隔开。
。此方法可以算出两个集合中的并集和非并集
for (String s : acctitleIdArray) {
list.add(s);
}
List<String> existList = new ArrayList<String>(limitSubList).retainAll(list);
List<String> notExistList = list.removeAll(limitSubList);StringBuilder existBuf = new StringBuilder();
for (String s : existsList) {
existBuf.append(s).append(",");
}
if (existBuf.length()>0) {existBuf.delete(existBur.length()-1, existBur.length());}StringBuilder notExistBuf = new StringBuilder();
for (String s : notExistList) {
notExistBuf.append(s).append(",");
}
if (notExistBuf.length()>0) {notExistBuf.delete(notExistBuf.length()-1, notExistBuf.length());}
String[] result = new String[]{existBuf.toString(), notExistBuf.toString()};
return result;