nsr
nsr

Reputation: 115

how to convert list<objct> into string []

Is it possible to convert this type List<Jadval> into String[] wordList? I read the words from database with like this :

public static List<Jadval> jadvalList = new ArrayList<Jadval>();

JadvalDB jadvalDB = new JadvalDB(GameActivity.this);
    jadvalList = jadvalDB.getWords(myPos + 1);

and now i want to put jadvalList values into String[] wordList. i use this code to set the values :

for (int i = 0; i < jadvalList.size(); i++) {
        wordList[i] = (jadvalList.get(i).toString());
    }

but I get the error that wordList is empty . any idea?

Upvotes: 0

Views: 47

Answers (1)

Volha
Volha

Reputation: 31

You can use streams and complete it in one line like this:

String[] wordList = jadvalList.stream().map(a->a.toString()).toArray(String[]::new);

Upvotes: 3

Related Questions