forked from Red-0111/Anything-Repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayList 4
34 lines (26 loc) · 773 Bytes
/
ArrayList 4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Java Program to Convert ArrayList to Array
// using toArray() Method
// Importing required classes
import java.util.*;
// Main class
class GFG {
// Main driver method
public static void main(String[] args)
{
// Creating an empty ArrayList of string type
ArrayList<String> al = new ArrayList<String>();
// Populating the ArrayList by custom elements
al.add("Anshul Aggarwal");
al.add("Mayank Solanki");
al.add("Abhishek Kelenia");
al.add("Vivek Gupta");
// Converting above List to array using toArray()
// method and storing it in an string array
String k[] = al.toArray(new String[al.size()]);
// Iterating over above string array
for (String str : k) {
// Printing the elements in above array
System.out.println(str);
}
}
}