Java List convert to an array

Description

Java List convert to an array


import java.util.Arrays;
import java.util.List;

public class Main {
  public static void main(String[] a) {
    List<String> list = Arrays.asList(new String[] { "CSS", "HTML", "C++", "Java" });

    Object[] objArray = list.toArray();

    System.out.println(Arrays.toString(objArray));
    //from w ww.j  a  v a2s .c  o  m

    String[] strArray = (String[]) list.toArray(new String[list.size()]);

    System.out.println(Arrays.toString(strArray));
    
  }
}



PreviousNext

Related