- #1
sinhasiha
- 2
- 0
I have two ArrayLists and I want to check if the items stored in one list is also in the other and if it is, store it in a third ArrayList. My problem is that each object from list two is getting stored in list three.
The lists contain:
List one: 50 items
List two: 15 items
Of the 15 items in list two, 10 of them are in List one and these are the ten that I want to store in List three.
Here is the code I have came up with but something is not right. I didn't see it necessary to show the rest of the code since I know storing the objects in list one and two is working properly.
view plainprint?
Note: Text content in the code blocks is automatically word-wrapped
Java:
for (Items item : listTwo){
listThree.add(listOne.contains(item) ? 1 : 0, item);
}
¸.•°*”˜˜”*°•. ¸.•°*”˜˜”*°•.¸
..¸.•°*”˜˜”*°•Thank you.•°*”˜˜”*°•.¸
————————————————
The lists contain:
List one: 50 items
List two: 15 items
Of the 15 items in list two, 10 of them are in List one and these are the ten that I want to store in List three.
Here is the code I have came up with but something is not right. I didn't see it necessary to show the rest of the code since I know storing the objects in list one and two is working properly.
view plainprint?
Note: Text content in the code blocks is automatically word-wrapped
Java:
for (Items item : listTwo){
listThree.add(listOne.contains(item) ? 1 : 0, item);
}
¸.•°*”˜˜”*°•. ¸.•°*”˜˜”*°•.¸
..¸.•°*”˜˜”*°•Thank you.•°*”˜˜”*°•.¸
————————————————
Last edited: