Write a Java application CountryList. In the main method, do the following: 1. Create an array list of Strings called countries. 2. Add "Canada", "India", "Mexico", "Peru" in that order. 3. Use the enhanced for loop to print all countries in the array list, one per line. 4. Add "Spain" at index 1 5. Replace the element at index 2 with "Vietnam". You must use the set method. 6. Replace the next to the last element with "Brazil". You must use the set method. You lose one point if you use 3 in the set method. Do this in a manner that would replace next to the last element, no matter the size of the array list. 7. Remove the object "Canada" Do not remove at an index. Your code should work if "Canada" was at a different location. There is a version of remove method that will
Write a Java application CountryList. In the main method, do the following: 1. Create an array list of Strings called countries. 2. Add "Canada", "India", "Mexico", "Peru" in that order. 3. Use the enhanced for loop to print all countries in the array list, one per line. 4. Add "Spain" at index 1 5. Replace the element at index 2 with "Vietnam". You must use the set method. 6. Replace the next to the last element with "Brazil". You must use the set method. You lose one point if you use 3 in the set method. Do this in a manner that would replace next to the last element, no matter the size of the array list. 7. Remove the object "Canada" Do not remove at an index. Your code should work if "Canada" was at a different location. There is a version of remove method that will
Chapter8: Arrays
Section: Chapter Questions
Problem 9PE
Related questions
Question
Important:
not using an array list
• not using an enhanced for loop
• using index to remove “Canada”
RUN OUT LIKE THE EXPECTED PICTURE
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 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
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT