How can i put a list to array

本秂侑毒 提交于 2020-03-25 17:53:32

问题


How can i put a list of strings, type string

in

  String countryList[] = {a};

a is the variable that have the list

so, it will be

  String countryList[] = {"heyyesGabon","heyyesGibraltar","heyyesGuinea"}; //and the others

this list comes from console.log in javascript

it always save the last item


回答1:


From List to String array

String [] countryArray = countryList.toArray(new String[0]);

From String array to List

List<String> list = Arrays.asList(array);



回答2:


You can use in-build function list.toArray(stringArray); it will return String[].

String countryList[] = new String[list.size()];
countryList = list.toArray(countryList);

Hope this will help you.



来源:https://stackoverflow.com/questions/60699878/how-can-i-put-a-list-to-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!