Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)

Can anyone help me how I can able to convert the arraylist into an array? I tried with the below code but it is throwing an error.

Code:

String dsf[] = new String[al.size()];              

for(int i =0;i<al.size();i++){

  dsf[i] = al.get(i);

}

Error:

Ljava.lang.String;@57ba57ba

1 Answer

0 votes
by (26.7k points)

You can use the below the code to achieve that:

List<String> list=new ArrayList<String>();

list.add("Intellipaat");

list.add("Software");

list.add("Solution");

String names[]=list.toArray(new String[list.size()])

I hope this will help.

Want to become a Java Expert? Join Java Certification now!!

Want to know more about Java? Watch this video on Java Course | Java Tutorial for Beginners:

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Sep 23, 2019 in Java by Ritik (3.5k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...