#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] + " "); } } }
#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] + " "); } } }
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 19RQ
Related questions
Question
#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<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
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 2 images
Knowledge Booster
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.Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,