How to create array or list of Lists in Java?
I have:
List<Item> rows = new ArrayList<Item>();
rows.add(new Item("a"));
rows.add(new Item("b"));
... and how to create array of lists like this above?
List<Item> lists[] = {};
lists[0] = rows;
Here is what I am trying to do:
public class MainActivity extends FragmentActivity {
public static List<List<Item>> lists;
String tabs[] = { "Tab 1", "Tab 2" };
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lists = new ArrayList<List<Item>>();
for (int i = 0; i < tabs.length; i++)
{
lists.add(i, init());
}
}
public List<Item> init()
{
List<Item> rows = new ArrayList<Item>();
rows.add(new Item("test"));
return rows;
}
}
... and then I am trying to get that list by using:
MainActivity.lists.get(0);
staticblock.