Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is a quick review of how array elements are modified and accessed: 1. public class BasicArray{ 2. public static void main(String[] args) { 3.

Here is a quick review of how array elements are modified and accessed:

1. public class BasicArray{ 2. public static void main(String[] args) { 3. int[] basic = new int[4]; 4. for (int i=0; i

Method (Paramters) Return Value Type Description
add (E element) Boolean

Appends the specified element to the end of this list

add (int index, E element) Void

Inserts the specified element at the specified position in this list

get (int index) E

Returns the element at the specified position in this list

set (int index, E element) E

Replaces the element at the specified position in this list with the specified element. Returns the element previously at the specified position

size() int

Returns the number of elements in this list

1. What are the contents of the array at the end of running the BasicArray program shown in the previous step? 2. What two lines in the BasicArray class above where the array elements are being retrieved (i.e., accessed). 3. What two lines in the BasicArray class above where the array elements are being set to a value? In one of those two places where the array elements are set, the array element is being initialized (set for the first time), which one is that? 4. Now examine the ArrayList methods in the above table, a) Which method retrieves elements from the ArrayList? b) Which method replaces the value of an element that already exists in the ArrayList? c) Which two methods initializes the value of an element? d) How do the two methods in (c) differ? Which method(s) would be appropriate in the above Java program (after we convert it to work with ArrayLists)?

5. Now examine the for-loops in the above Java program. (assume that we have the have replaced the array with an ArrayList) a) Which ArrayList method should you use to control the for-loop iterations? b) Explain why the first for-loop cannot be controlled by that ArrayList method (but the other two for-loops can).

6. Before we convert the above code to an ArrayList, we will need to determine which package to import.Examine the second line of the API documentation: https://docs.oracle.com/javase/9/docs/api/java/util/ArrayList.html What package does ArrayList belong to?

7. ArrayLists only work with class types, not primitive types. You will need a wrapper class to create an ArrayList of integers. Which is the appropriate wrapper class to use here?

8. Find the API documentation for the wrapper class from this list of Java classes: https://docs.oracle.com/javase/8/docs/api/allclasses-noframe.html Which package does the wrapper class belong to?

9. Write the line of code to declare an ArrayList of four integers:

Please answer all part to each question, thank you!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 11G SQL

Authors: Joan Casteel

2nd Edition

1133947360, 978-1133947363

More Books

Students also viewed these Databases questions

Question

2. Develop a program for effectively managing diversity.

Answered: 1 week ago

Question

7. What is coaching? Is there only one type of coaching? Explain.

Answered: 1 week ago