A
A
Anton2018-07-10 11:14:56
Java
Anton, 2018-07-10 11:14:56

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

2 answer(s)
A
Alexey Cheremisin, 2018-07-10
@Anton238

Somehow, however.

ArrayList<String> coll1 = new ArrayList<>();
ArrayList<String> coll2 = new ArrayList<>();

coll1.add("MyObject");
coll2.add(coll1.remove(0)); // вот тут вся магия, удаляем нулевой элемент из коллекции и пушим его в другую

G
GavriKos, 2018-07-10
@GavriKos

You can write all this with pens, but it will not be very good.

Write two lines - not really?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question