Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Lab 6.6 Basic ArrayList Skills Array lists are objects that, like arrays, provide you the ability to store items sequentialy and recall items by index.
Lab 6.6 Basic ArrayList Skills Array lists are objects that, like arrays, provide you the ability to store items sequentialy and recall items by index. Working with array lists involves invoking Arraylist methods, so we will need to develop some basic skills. Let's start with the code helow: import java.util.Arraytiats public claas ArrayiiatRunner public static roid main(string args) ArrayLietstring> names ystem.out println (names) new ArrayLietestring>(); The main method imports jva.util.^rrayList and creates an arraylist that can hold strings. It also prints out the arraylist and, when it does, we see that the list is ermpty: . t1. Complete the following tasks by adding code to this skeleton program. If you are asked to print a value, provide a suitable label to identify it when it is printed. a Invokedd() to enter the folowing names in sequence: Aice, Bob, Conne, David, Edward, Fran, Gomez, Harry. Print the arraylist again. b) Use getto retrieve and print the first and last names. c) Print the aize of the arraytiat. d) Use aise ) to help you print the last name in the list. e) Use set to change "Alice" to "Alice B. Toklas Print the Araylist to venfy the change. f) Use the altemate fom of add to insert Doug" after "David. Print the arrayst again. g) Use an enhanced for loop to print each name in the Arraytist. h) Create a second Array.iat called namea2 that is built by calling the Arrayiat constructor that accepts another Arrayiat as an argument. Pass names to the constructor to build namea2. Then print the ArrayList. Call names.move (0) to remove the first elerment. Print names and aames2. Verify that Alice B. Toklas was removed fron aames, but not from names2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started