This question already has an answer here:
How can I convert a List
to an Array
in Java?
Check the code below:
ArrayList<Tienda> tiendas;
List<Tienda> tiendasList;
tiendas = new ArrayList<Tienda>();
Resources res = this.getBaseContext().getResources();
XMLParser saxparser = new XMLParser(marca,res);
tiendasList = saxparser.parse(marca,res);
tiendas = tiendasList.toArray();
this.adaptador = new adaptadorMarca(this, R.layout.filamarca, tiendas);
setListAdapter(this.adaptador);
I need to populate the array tiendas
with the values of tiendasList
.
This is works. Kind of.
Then the main method.
An alternative in Java 8:
Either:
or:
Note that this works only for arrays of reference types. For arrays of primitive types, use the traditional way:
You can use toArray() api as follows,
Values from the array are,
Best thing I came up without Java 8 was:
If anyone has a better way to do this, please share :)
I think this is the simplest way: