There is no dynamic allocation in Java
, Lists
are here on this purpose.
For example, List
, ArrayList
, LinkedList
...
Used this way :
// Declaring, initializing the list
ArrayList<News> list = new ArrayList<News>();
// Adding a news :
News news = new News("1","news 1","this is news 1");
list.add(news);
And if you already have an array of News
(in your example news_data
), you can quickly fill your list to begin :
for(News n : news_data) { list.add(n); }