#Steps: Create a Main class. Declare an ArrayList in the main() method and store the given values in it. Create an array called output of the size of the ArrayList. Iterate through for-loop to get each element from the array List and load it into the array using the get() method of the list. Print the array to see the loaded elements.     import java.util.ArrayList; import java.util.List; public class Main {     public static void main(String[] args) {                 List nameList = new ArrayList();        nameList.add("Robert");        nameList.add("Samson");        nameList.add("Alex");        nameList.add("William");                    System.out.println("Elements of List: " + nameList);                 // Create an array of the same size as nameList Hint: use size() method                   // Fetch the elements from the nameList and insert into newly created array                  // Hint: Use get() method to fetch the elements from arraylist and use for loop                  //                 System.out.print("Elements of Array: ");         for (int i = 0 ; i < output.length ; i++){             System.out.print(output[i] + "  ");         }     } }

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 19RQ
icon
Related questions
Question

#Steps:

  1. Create a Main class.

  2. Declare an ArrayList in the main() method and store the given values in it.

  3. Create an array called output of the size of the ArrayList.

  4. Iterate through for-loop to get each element from the array List and load it into the array using the get() method of the list.

  5. Print the array to see the loaded elements.

 

 

import java.util.ArrayList;
import java.util.List;
public class Main {

    public static void main(String[] args) {
        
       List<String> nameList = new ArrayList<String>();

       nameList.add("Robert");
       nameList.add("Samson");
       nameList.add("Alex");
       nameList.add("William");
    
      
       System.out.println("Elements of List: " + nameList);

       
        // Create an array of the same size as nameList Hint: use size() method 
        

        // Fetch the elements from the nameList and insert into newly created array

        
        // Hint: Use get() method to fetch the elements from arraylist and use for loop

        

        // 

      
        System.out.print("Elements of Array: ");
        for (int i = 0 ; i < output.length ; i++){
            System.out.print(output[i] + "  ");
        }

    }
}
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,