Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions