Question

Java Question: Describe what is an ArrayList (API) in Java. Provide an example code segment to...

Java Question:

Describe what is an ArrayList (API) in Java. Provide an example code segment to describe as well.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In Java is used to store dynamically sized collection of elements. Contrary to Arrays that are fixed in size, an ArrayList grows its size automatically when new elements are added to it.ArrayList is a part of collection framework and is present in java.util package.

===================================================================================

import java.util.ArrayList;


public class Driver {

    public static void main(String[] args) {
        // Creating an ArrayList of String
        ArrayList<String> countries= new ArrayList<>();

            // Unlike array where we can store only fixed number of elements
           // in array list we can keep on adding elements without the
          // need to resize the array
         // ArrayList supports dynamic arrays that can grow as needed
        countries.add("US");
        countries.add("Brazil");
        countries.add("England");
        countries.add("China");


        System.out.println(countries);

        // Adding an element at a particular index in an ArrayList
          
        countries.add(2, "France");

        System.out.println(countries);



    }
}

======================================================================

Add a comment
Know the answer?
Add Answer to:
Java Question: Describe what is an ArrayList (API) in Java. Provide an example code segment to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT