How To Copy ArrayList To Array
In this example we learn how to make a array from arraylist. we will use toArray() method for this purpose. This method return a array from arraylist
import java.util.ArrayList;
public class ArrayListToArray {
public static void main(String[] args) {
ArrayList<String> arr = new ArrayList<String>();
// add element in arraylist
arr.add("c");
arr.add("php");
arr.add("html");
arr.add("java");
String[] brr = new String[arr.size()];
//Returns an array containing all of the elements in this
//list in proper sequence (from first to last element).
arr.toArray(brr);
for (int i = 0; i < brr.length; i++) {
System.out.println(brr[i]);
}
}
}
Output:
c
php
html
java
Related Posts:
How to count number of element in ArrayList
How to insert element in arraylist
How to use retailAll in arraylist
No comments:
Post a Comment