Question: Java: There is no start file this time. You create a class called PracticeWithArrayLists with a main method In the main method, do the following

Java:

There is no start file this time. You create a class called PracticeWithArrayLists with a main method In the main method, do the following

Create an ArrayList of Strings called zoo

Add "tiger", "lion", "elephant", "kangaroo" in that order.

Add "giraffe" at position 1

Replace the element at index 4 with "zebra" Use the set method

Replace the next to the last element with "wallaby". Do this in a manner that would replace the next to the last element, no matter the size of the array list. Think about how to find the last element in an array list, then find the index of the next to the last element and use the set method.

Remove "lion"

Get and print the 0th element followed by "***"

Print the elements on one line in the [xxx, yyy, ...] format

Print the entire array list one element to a line (use the enhanced for loop)

Note: You must use an ArrayList and its methods. Do not fake it by just printing the correct strings. You will know how to use these methods in a situation where the output can not be faked.

Note: There is a version of remove method that will remove a specific object. Use that. Here is the code to remove target from the ArrayList called stuff

stuff.remove(target); 

Note: To print an ArrayList, use its toString method like this

System.out.println(stuff); 

Please check the answer here: http://www.codecheck.it/files/17073002088g0ivs5k4mw2kz4j2cq68ii8t

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!