2

这个问题需要相等)
但是我有两个 JSONArray,我将检查这些数组中存在的字符串并找到不同的元素。

通常我可以看到这样的数组的值:

JSONArray array1 = getArray1();
JSONArray array2 = getArray2();

// array1 = 12,23,44,66
// array2 = 23,44,66,90

for (int i=0; i < array1.length(); i++) {
   String name=array1.getString(i);
}

我需要找到存在于array1但不存在于array2. 数组元素是字符串。

4

1 回答 1

4

Create two different Set starting from the two array, then call

firstSet.removeAll(secondSet);

the result will be the difference between the two arrays.

the doc for removeAll says:

Removes from this set all of its elements that are contained in the specified collection

于 2013-05-15T13:10:51.493 回答