How to convert arrayList to array?

There are lot of times where we need to convert arrayList to array, here it is a simple way to do this.
ArrayList have one method called toArray() which helps in converting arrayList to array as follows :


List listVersion = new ArrayList();

listVersion.add("Abc");
listVersion.add("XYz");
listVersion.add("LMN");
listVersion.add("pqr");

String [] arrayVersion = listVersion.toArray(new String[listVersion.size()]);

Here you can have your own class instead of String.
Share on Google Plus

About Pranav

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment