Question: This assignment is in Java: import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Scanner; public class ArrayListExcercise { public static void main(String[] args) {

This assignment is in Java:

import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Scanner;

public class ArrayListExcercise { public static void main(String[] args) { //1. Add all the colors in the colors.txt file to an ArrayList. //Use a Scanner class to open the "colors.txt" file. //Read the whole file adding each color to an ArrayList. //Your ArrayList should store String's. e.g. ArrayList list = new ArrayList<>(); //Your Scanner object should call the "next()" method to get the next color //as a string. //In order to read the whole file you will have to use a while loop to determine //if there is more data in the file //2.Iterate through the ArrayList and print the values out to the console. //a. You can use any method to iterate through the loop, for loop, // enhanced for loop.

//3.Insert the String Black into index 2. See add method. //a.Print the values of the ArrayList to the console using a loop //4. Retrieve the String at index 3 and print it to the console. See get method. //5. Remove the String at index 0 from the ArrayList. See remove method. //a. Print the values of the ArrayList to the console using a loop //6. Update the array element at index 3 with the String Tan. See set method. //a. Print the values of the ArrayList to the console using a loop

colors.txt:

White Aquamarine Azure Bisque Blue Brown Burlywood Blue Chartreuse Chocolate Coral Cornsilk Cyan Goldenrod Green Orange Orchid Gray Pink Blue

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!