Question: Java arrays have a significant shortcoming. They cannot be resized after they have been instantiated. This can be a major problem, since you often don't
Java arrays have a significant shortcoming. They cannot be resized after they have been instantiated. This can be a major problem, since you often don't know how many elements a list of items will need when creating it One strategy is to start out with a small number of elements, then create a larger array when more space is needed, and copy the old array into the new one. This can be a hassle, and complicates the code, however. ArrayList performs this operation automatically, hiding the details inside a class, freeing up valuable "programmer cycles" for more important tasks Another drawback with arrays is that in many cases you have to search for the element that you want. HashMap provides a way to store and look up objects using a "key" value. For example, you might want to have a list of student records, and be able to look up a student by name. HashMap gives you this functionality rrayLists Array List is a " generic", also called a "parameterized type" This means that you can declare different kinds of Array List to hold different object types. Declaring a generic in Java is done with the angle bracket notation For example, The following line of code creates a ArrayList of Strings: ArrayList
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
