java后台合并数组并去重

public static void main(String[] args) {
String[] userId = {“1”, “2”, “3”};
String[] userId2 = {“2”, “3”, “4”};
String[] userId3 = {“3”, “5”, “6”};
List uList = new ArrayList<>();
CollUtil.addAll(uList, userId);
CollUtil.addAll(uList, userId2);
CollUtil.addAll(uList, userId3);
String[] res = uList.stream().distinct().toArray(String[]::new);
for (String s : res) {
System.out.println(s);
}
}

你可能感兴趣的:(java)