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.
Either:
or:
Note that this works only for arrays of reference types. For arrays of primitive types, use the traditional way:
Update:
It is recommended now to use
list.toArray(new Foo[0]);, notlist.toArray(new Foo[list.size()]);.From JetBrains Intellij Idea inspection: