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());
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
Get Answers For Free
Most questions answered within 1 hours.