I have an array:
File [] temp=null;
And I have an arrayList
of File
type:
List <File> tempList = new ArrayList <File>();
Now I want to add the content from temp
to tempList
. So anyone can please tell me How do I this?
I have an array:
File [] temp=null;
And I have an arrayList
of File
type:
List <File> tempList = new ArrayList <File>();
Now I want to add the content from temp
to tempList
. So anyone can please tell me How do I this?
Try this
tempList.addAll(Arrays.asList(temp));
If you are not going to update the content of the array (add/removing element), it can be as simple as
List<File> tempList = Arrays.asList(temp);
Of course, if you want a list that you can further manipulate, you can still do something like
List<File> tempList = new ArrayList<File>(Arrays.asList(temp));
You can iterate through the array and add each element to the list.
for (File each : temp)
tempList.add(each);