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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started