I have 2 ArrayList, which are periodically filled with data according to the following principle:
The first launch: ArrayList1 contains 3 numbers: 111, 222, 333; ArrayList2 contains 3 numbers: 111, 222, 333; ArrayList1 is cleared; ArrayList1 gets all the values of ArrayList2; ArrayList2 is cleared;
The second launch: ArrayList1 contains: 111, 222, 333; ArrayList2 contains: 444, 111, 222; ArrayList1 is cleared; ArrayList1 gets all the values of ArrayList2; ArrayList2 is cleared;
The third launch: ArrayList1 contains: 444, 111, 222; ArrayList2 contains: 555, 444, 111; ArrayList1 is cleared; ArrayList1 gets all the values of ArrayList2; ArrayList2 is cleared.
And so on. That is, new values periodically appear and "shift" the old data. The question is: how do you add these new values to ArrayList3 each time? That is, add a check: if new values have appeared (their number is not known in advance), then enter them into ArrayList3.
Listhas acontains()method that returnstrueif the object is in the list. Using this method, you can check if the object is already in the list. - Vladyslav Matviienko