Wednesday, 2 October 2013

Java: turning an arraylist into an array with an added element

Java: turning an arraylist into an array with an added element

I know that the code to turn an arraylist into an array is:
private String[] arrayLst_to_array(ArrayList<String> al) {
String[] arr = new String[al.size()];
arr = al.toArray(arr);
return arr;
}
But I want my new array to have a certain string in the beginning and then
after that, I want the rest of the arraylist.
I know that I could just add the string that I want to the beginning of
the arraylist and then convert it, but is there a more efficient way?

No comments:

Post a Comment