场景:可拆成数组的字符串,若需要去掉重复元素的一种方法(目测有效果,若要使用得临床再验证)
代码:
public class MergeString { public static void main(String[] args) { String str1 = "02,01,03"; String str2 = "01,03,04"; String str3 = str1 +","+ str2; String[] arr3 = str3.split(","); Set<String> set = new HashSet<>(); for (String string : arr3) { set.add(string); } for (String str : set) { System.out.println(str); } } }