Answer the question
In order to leave comments, you need to log in
What method from ArrayList allows you to move an object from one collection to another?
And also - who knows how to find the answer to this question yourself? I know what this method does, but I forgot the name. It takes a long time to scroll the oracle docks, but there are no results for my question in Google.
PS I need an element from collection1 to appear in collection2. The same (there is an object with fields). And removed from collection1. You can write all this with pens, but it will not be very good.
Answer the question
In order to leave comments, you need to log in
Somehow, however.
ArrayList<String> coll1 = new ArrayList<>();
ArrayList<String> coll2 = new ArrayList<>();
coll1.add("MyObject");
coll2.add(coll1.remove(0)); // вот тут вся магия, удаляем нулевой элемент из коллекции и пушим его в другую
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question