Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The ArrayList class creates an array that can resize on demand. Once you learn about ArrayList, there is little reason to use arrays. The container

The ArrayList class creates an array that can resize on demand. Once you learn about ArrayList, there is little reason to use arrays. The container allocates more memory automatically as more elements are added.

Write a test program that does the following:

  1. Create a new empty ArrayList of String type called testList
  2. Print the current size of testList.
  3. Add at least 5 elements to testList.
  4. Print testList. ArrayList has a toString method so its easy to print.
  5. Using get(0), print the first element of testList.
  6. Print the last element of testList. This time, do no use a constant to get the last element, use testList. Size().
  7. Use a for loop to print each element of testList.
  8. Use a for-each loop to print each element of testList.
  9. Use Collections.sort(testList) to sort your ArrayList.
  10. Use the testList.remove(0) method to remove the first element of the list. remove(0). Put this call inside a println statement so you can observe the return value. Print testList.
  11. Use the remove method to remove a specific string by its string value. Put this call inside a println statement so you can observe the return value. Print testList.

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

Step: 3

blur-text-image

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

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

More Books

Students also viewed these Databases questions