Android - Convert arrayList to String []

Asked

Viewed 51 times

0

Good morning guys, I need to convert a ArrayList for a String[].

I could not make it work. Just returns me a giant string. Follow my code

public List<Item> geral(){
    buscaLatLong();
    List<String> nomes = new ArrayList<String>();
    String[] namesArr = nomes.toArray(new String[resuladoLista.size()]);

    List<Item> item = new ArrayList<>();
    String listagem[] = namesArr;



    for (int i = 0; i<listagem.length; i++){
        Item item = new Item();
        item.setNome(listagem[i]);
        item.setNum(String.valueOf(i+1));
        itemList.add(item);
    }

    return itemList;
}

I did a test with a String fixed in the format below worked perfectly

 String listagem[] = {"Teste1",
                "Teste2",
                "Teste3",
                "Teste4"};

The result list is as private static ArrayList resuladoLista; How can I convert mine resuladoLista for a string identical to listagem[]?

  • Welcome, ask the question how the resuladoLista.

1 answer

0

Good afternoon!

Try with the class ArrayUtils as follows

String[] fruitsArr = ArrayUtils.toStringArray(fruitsList);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.