C
C
cot0322016-01-13 12:43:08
Java
cot032, 2016-01-13 12:43:08

How to write an object to an ArrayList?

There is a cycle

for (int i = 0; i < 10; i++) {
               	field.moveAll(); // выводит объекты в консоль, метод реализован в классе Field
       	        Thread.sleep(10);
}

How to write these objects to ArrayList?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Riard Brugekaaim, 2016-01-13
@cot032

In general, ArrayList has setAll / addAll () methods.
Since objects can be iterated over in for, it can be charged there as well. These methods chew on everything with the Serializable interface.
In other words:
Since field is a self-written class, then just add a method that returns objects, like this:
array.addAll(field.getObjects());

V
Vasily, 2016-01-13
@Applez

In general, it’s rather strange, I would like to see the whole class.
Is there a getter for objects?
If there is, use it to get it and add it all at once to the sheet using the addAll() method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question