Tutorialspoint

Create a new ArrayList from another collection in Java

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Demo {
   public static void main(String args[]) throws Exception {
      String str[] = { "John", "Macy", "Peter", "Susan", "Lucy" };
      List aList = new ArrayList(Arrays.asList(str));
      System.out.println("The ArrayList elements are: " + aList);
   }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.