除去,如何比較2 Java字符串數組,如果有即時具有2字符串數組相同的值
str1[] = {"a","b","aa","c"}
和
str2[] = {"aa","a","b","c","d"}
我如何比較和如果同時存在於除去值串[],預期的結果,STR3 [] = { 「d」}
由於事先
除去,如何比較2 Java字符串數組,如果有即時具有2字符串數組相同的值
str1[] = {"a","b","aa","c"}
和
str2[] = {"aa","a","b","c","d"}
我如何比較和如果同時存在於除去值串[],預期的結果,STR3 [] = { 「d」}
由於事先
ts1在這些操作之後會有「d」。
String str1[] = {"a","b","aa","c"};
String str2[] = {"aa","a","b","c","d"};
TreeSet ts1 = new TreeSet(Arrays.asList(str2));
ts1.removeAll(Arrays.asList(str1));
轉換陣列到一個列表,並將其添加到一套會自動刪除重複。使用Set接口的toArray()方法將元素作爲數組獲取。
String[] str1 = {"a","b","aa","c"};
String[] str2 = {"aa","a","b","c","d"};
Set set = new HashSet();
set.addAll(Arrays.asList(str1));//add first array to set, removes duplicates
set.addAll(Arrays.asList(str2));//add second array to set, removes duplicates
String[] str3 = (String[])set.toArray(new String[set.size()]);//convert back to array
喜專家,終於讓我找到結果我的問題,這是清單STR3 = ListUtils.subtract(Arrays.asList(STR1),Arrays.asList(STR2)); – Apache 2010-11-28 07:23:23