Question

Describe the effect of each of the following operations on object myList . What is the...

Describe the effect of each of the following operations on object myList .

What is the value of myList.size() after each operation?

Figure the initial list consist of the following string names:

Bashful

Awful

Doc

Jumpy

Happy

Dopey.

Answer both questions.

myList.add("Pokey");

myList.add("Campy");

int i = myList.indexOf("Happy");

myList.set(i, "Bouncy");

myList.remove(myList.size() - 2);

String temp = myList.get(1);

myList.set(1, temp.toUpperCase());

Homework Answers

Answer #1

Solution

Starting size is 6

myList.add("Pokey");

It add elements to end of the "myList"

after adding size is 7

myList.add("Campy");

It add elements to end of the "myList"

after adding size is 8

int i = myList.indexOf("Happy");

it returns the value 4 and it stored to integer 'i"

myList.set(i, "Bouncy");

then we set the element i(4) to "Bouncy" and size is 8

myList.remove(myList.size() - 2);

it will remove the item 6 that is "Pokey" and size is 7

String temp = myList.get(1);

now it will store "awful" in temp and size is 7

myList.set(1, temp.toUpperCase());

Now sets item1 to "AWFUL" and replacing "awful

therefore

final size is 7

---

all the best

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Do a theta analysis and count the number of computations it performed in each function/method of...
Do a theta analysis and count the number of computations it performed in each function/method of the following code: import java.io.*; import java.util.Scanner; class sort { int a[]; int n; long endTime ; long totalTime; long startTime; static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public sort(int nn) // Constructor { a = new int[nn]; n = nn; endTime= 0; totalTime =0; startTime =0; } public static void main(String args[]) throws IOException { System.out.print("\nEnter number of students: "); int nn =...
IN JAVA Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort: <-- (I need the...
IN JAVA Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort: <-- (I need the code to be written with these) I need Class river, Class CTRiver and Class Driver with comments so I can learn and better understand the code I also need a UML Diagram HELP Please! Class River describes river’s name and its length in miles. It provides accessor methods (getters) for both variables, toString() method that returns String representation of the river, and method isLong()...
C++ See the provided specification files. Complete the implementation for each as a separate file. void...
C++ See the provided specification files. Complete the implementation for each as a separate file. void seen(std::string); If there is already a Word object in the Words list, then the number of occurrences for this word is incremented. If there is no Word object for this word already, create a new word object with occurrence =1, and insert this object into the list of Word objects. std::string getNextWord(); Returns the next word of the list and sets the currentItem pointer...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...
8.15 *zyLab: Method Library (Required & Human Graded) This code works but there are some problems...
8.15 *zyLab: Method Library (Required & Human Graded) This code works but there are some problems that need to be corrected. Your task is to complete it to course style and documentation standards CS 200 Style Guide. This project will be human graded. This class contains a set of methods. The main method contains some examples of using the methods. Figure out what each method does and style and document it appropriately. The display method is done for you and...
For each of the following situations, describe the anticipated effect on blood pressure and the physiological...
For each of the following situations, describe the anticipated effect on blood pressure and the physiological basis of the response: (1) anticipation to giving a lecture/speech/presentation, (2) cardiac arrest, (3) atherosclerosis, and (4) femoral artery bleed.
I need a method for public void ****************** write the method “insertDoubles” that for each value...
I need a method for public void ****************** write the method “insertDoubles” that for each value found in an integer linked list it inserts that value doubled after the original. The method should return nothing and take in in no parameters. If the list is empty, then the method should do nothing. To avoid infinite loops you need to move the iterator past the newly inserted value. here is the provided code public class Question02 { public class ListNode//public for...
I'm currently stuck on Level 3 for the following assignment. When passing my program through testing...
I'm currently stuck on Level 3 for the following assignment. When passing my program through testing associated with the assignment it is failing one part of testing.   Below is the test that fails: Failed test 4: differences in output arguments: -c input data: a b c -c expected stdout: b observed stdout: a b expected stderr: observed stderr: ./test: invalid option -- 'c' Unsure where I have gone wrong. MUST BE WRITTEN IN C++ Task Level 1: Basic operation Complete...
Given the following code: public void expand(Object a) {     // assume element has enough capacity...
Given the following code: public void expand(Object a) {     // assume element has enough capacity     for (int i = size - 1; i >= 0; i--) {         element[4 * i + 3] = a;         element[4 * i + 2] = a;         element[4 * i + 1] = a;         element[4 * i] = element[i];      }      size = 4 * size; } element is a one-dimensional array that stores elements of the type Object....
For each of the questions below, explain the physiological mechanisms that lead to changes in breathing...
For each of the questions below, explain the physiological mechanisms that lead to changes in breathing following a bout of hyperventilation. i) What happens to arterial PCO2 in the time after the hyperventilation? Why does it change? ii) List the names and the locations of the receptors that detect this change in PCO2? iii) Name the brain centre that interprets the information sent from these receptors and identify its location in the CNS. (1 mark)
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT