Java code for converting Array List to String Array using Java
- import java.util.ArrayList;
- import java.util.Arrays;
- public class Demo
- {
- public static void main(String args[])
- {
- ArrayList < String > aList = new ArrayList < String > ();
- aList.add("Seconds");
- aList.add("Minutes");
- aList.add("Hours");
- aList.add("Days");
- aList.add("Weeks");
- aList.add("Months");
- aList.add("Years");
- Object[] obj = aList.toArray();
- String[] str = Arrays.copyOf(obj, obj.length, String[].class);
- System.out.println("ArrayList converted to String array:");
- for (int i = 0; i < str.length; i++)
- {
- System.out.println(str[i]);
- }
- }
- }
Thank you, keep learning and sharing