Array lists are objects that, like arrays, provide you the ability to store items sequentially and recall items by index. Working with array lists involves invoking ArrayList methods, so we will need to

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

This is the file :

 

 

Array lists are objects that, like arrays,
provide you the ability to store items
sequentially 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 below. Create a
new Eclipse project named
Lab_Project_26. Then,
1. download the JavaArrayLists.java source
code file to the project folder
2. in Eclipse, import/open the source code
file for editing
3. enter your name in the comment block
near the top of the file
4. add the required code as described below
The main method declares and creates an
ArrayList with the identifier names that
can hold strings. It also prints out the
ArrayList. When we compile and execute
this code, we see that the ArrayList is
empty: [].
Complete the following tasks by adding code
to this skeleton program. If you are asked to
print a value or an array list, provide a
suitable label to identify it when it is printed
(e.g., last name: Harry, or names: []).
a. Call the ArrayList's add() method to
enter the following names in sequence:
Alice, Bob, Connie, David, Edward, Fran,
Gomez, Harry.
Print the ArrayList again.
b. Call the ArrayList's get() method to
retrieve and print the first and last names.
c. Print the size() of the ArrayList.
d. Use size() to help you print the last
Transcribed Image Text:Array lists are objects that, like arrays, provide you the ability to store items sequentially 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 below. Create a new Eclipse project named Lab_Project_26. Then, 1. download the JavaArrayLists.java source code file to the project folder 2. in Eclipse, import/open the source code file for editing 3. enter your name in the comment block near the top of the file 4. add the required code as described below The main method declares and creates an ArrayList with the identifier names that can hold strings. It also prints out the ArrayList. When we compile and execute this code, we see that the ArrayList is empty: []. Complete the following tasks by adding code to this skeleton program. If you are asked to print a value or an array list, provide a suitable label to identify it when it is printed (e.g., last name: Harry, or names: []). a. Call the ArrayList's add() method to enter the following names in sequence: Alice, Bob, Connie, David, Edward, Fran, Gomez, Harry. Print the ArrayList again. b. Call the ArrayList's get() method to retrieve and print the first and last names. c. Print the size() of the ArrayList. d. Use size() to help you print the last
b. Call the ArrayList's get() method to
retrieve and print the first and last names.
c. Print the size() of the ArrayList.
d. Use size() to help you print the last
name in the list.
e. Use set() to change "Alice" to "Alice B.
Toklas".
Print the ArrayList to verify the change.
f. Use the alternate form of add () to insert
"Doug" after "David".
Print the ArrayList again.
g. Use a loop (instead of a single call to
System.out.println) to print each
name in the ArrayList.
h. Create a second Array List called names2
that is built by calling the ArrayList
constructor that accepts another
ArrayList as an argument.
Pass names to the ArrayList
constructor to build names2.
Then print the ArrayList again.
i. Call names. remove(0) to remove the
first element from the original
ArrayList.
Print names and names2.
Verify that "Alice B. Toklas" was removed
from names, but not from names2.
Transcribed Image Text:b. Call the ArrayList's get() method to retrieve and print the first and last names. c. Print the size() of the ArrayList. d. Use size() to help you print the last name in the list. e. Use set() to change "Alice" to "Alice B. Toklas". Print the ArrayList to verify the change. f. Use the alternate form of add () to insert "Doug" after "David". Print the ArrayList again. g. Use a loop (instead of a single call to System.out.println) to print each name in the ArrayList. h. Create a second Array List called names2 that is built by calling the ArrayList constructor that accepts another ArrayList as an argument. Pass names to the ArrayList constructor to build names2. Then print the ArrayList again. i. Call names. remove(0) to remove the first element from the original ArrayList. Print names and names2. Verify that "Alice B. Toklas" was removed from names, but not from names2.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY