O
O
Orkhan Hasanli2018-08-27 04:37:39
Java
Orkhan Hasanli, 2018-08-27 04:37:39

How can I add additional information in ArrayList?

Hello!
In an ArrayList I store a pojo Website containing 4 rows.
In the first method in List ArrayList<> I add the first 3 lines (accordingly, the first constructor contains 3 lines). In the second method, I add the last line to the ArrayList<> (+1 extra constructor with the last line). And it turns out that the 4th line is not added to the 3rd previous ones, but additional ones are created. objects null null null line 4. How can you add objects to an ArrayList and still make them look like line 1, line 2, line 3, line 4 (taking into account that they are obtained and added in different methods)? I hope I was able to explain... If necessary, I will provide the source code...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
EVGENY T., 2018-08-27
@azerphoenix

https://docs.oracle.com/javase/7/docs/api/java/uti...
It is possible to add an element at a specific position by passing the index as the first parameter and the object as the second.
arrayList.add(4, myObj);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question