Answer to Question #309538 in Java | JSP | JSF for Kyle

Question #309538

Write a Java program to convert an array to an ArrayList, and an ArrayList to an array.


1
Expert's answer
2022-03-15T02:57:30-0400
public static void main(String[] args) {
    Integer[] array = {1, 2, 3, 3, 4};

    //Array to ArrayList
    List<Integer> list = Arrays.asList(array);
    for (Integer x : list)
        System.out.print(x + " ");

    System.out.println();

    //ArrayList to array
    Integer[] arr = new Integer[list.size()];
    arr = list.toArray(arr);
    for (Integer x : arr)
        System.out.print(x + " ");
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS