2

(This question needs for the equality)
But I have two JSONArray and I will check the strings that exists in these arrays and find the different elements.

Normally I can see the values of the arrays like this:

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);
}

I need to find elements that exists in array1 but doesn't exist in array2. Array elements are strings.

1 Answer 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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.