DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Sandeep kamboj
Sandeep kamboj

Posted on

Convert ArrayList<String>() To Stirng[] Array in Android

ArrayList list=new ArrayList<>();
list.add("A");
list.add("B");
list.add("C");
list.add("D");

String[] stringArr=TextUtils.join(",",list).split(",");

Top comments (1)

Collapse
 
ibibgor profile image
Oscar

Isn't it more performant to use the buildin method toArray(). So the code would be:

List<String> list = new ArrayList<>();
// add some data
String[] starr = list.toArray(new String[0]);

Build Anything...


Use any Linode offering to create something for the DEV x Linode Hackathon 2022. A variety of prizes are up for grabs, inculding $1,000 USD. πŸ‘€

β†’ Join the Hackathon <-