Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A. (1 points) Write a public void set(int i, string s) method that sets the element of the list at index i to the value

image text in transcribed

A. (1 points) Write a public void set(int i, string s) method that sets the element of the list at index i to the value s. That is, it should overwrite the existing element at i. Be sure to handle exceptional conditions appropriately. B. (1 points) Using a foreach loop, write a public boolean contains (String s) method that searches the list for an occurrence of a value equivalent to s (be careful with the kind of equality you use!). Return true to indicate that a string equivalent to s is contained in the StringArrayList, and return false to indicate that there is no value in our StringArrayList that is equivalent to s. The only variable you may declare is the string declared in the foreach loop: for (String v : array) { ... }. Do not declare any other variables (you will lose points)!!! C. (1 points) Write a public int indexof (String s) method that searches the list for the first occurrence of a value equivalent to s (be careful with what kind of equality you use!), and returns its index. Return -1 if the value is not found. D. (1 point each) Suppose you instantiate a new StringArrayList. What are the size and the length of the backing array: 1. Right after instantiating the list. 2. After you add () 10 items to this list. 3. After you remove(0) five times from this list. htt Page 1 of 2 1/17/21, 1:09 PM 4. After you add() 10 more items to this list. Assume each step happens in sequence (that is, for part 3, you've instantiated the list, added 10 items, and then removed five). A. (1 points) Write a public void set(int i, string s) method that sets the element of the list at index i to the value s. That is, it should overwrite the existing element at i. Be sure to handle exceptional conditions appropriately. B. (1 points) Using a foreach loop, write a public boolean contains (String s) method that searches the list for an occurrence of a value equivalent to s (be careful with the kind of equality you use!). Return true to indicate that a string equivalent to s is contained in the StringArrayList, and return false to indicate that there is no value in our StringArrayList that is equivalent to s. The only variable you may declare is the string declared in the foreach loop: for (String v : array) { ... }. Do not declare any other variables (you will lose points)!!! C. (1 points) Write a public int indexof (String s) method that searches the list for the first occurrence of a value equivalent to s (be careful with what kind of equality you use!), and returns its index. Return -1 if the value is not found. D. (1 point each) Suppose you instantiate a new StringArrayList. What are the size and the length of the backing array: 1. Right after instantiating the list. 2. After you add () 10 items to this list. 3. After you remove(0) five times from this list. htt Page 1 of 2 1/17/21, 1:09 PM 4. After you add() 10 more items to this list. Assume each step happens in sequence (that is, for part 3, you've instantiated the list, added 10 items, and then removed five)

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

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago