What is an array list

How to create an ArrayList from an array in Java

  1. What's a in Java?
  2. What is an “array list” in Java?
  3. Difference between and in Java
  4. Converting one to one using
  5. Converting an to using
  6. Converting a to with

This tutorial article introduces different methods to build from in Java. There are three different methods to convert a to to, such as, and.

Before proceeding with the demonstration, we should understand what a and an are and how they differ from each other.

What's a in Java?

A is a collection of a fixed number of similar types of data. For example, if we want to store the data of 50 books, we can create an “array” of type “string” that can hold 50 books. After creation, the length of the is fixed. One is the basic built-in functionality of Java.

What is an “array list” in Java?

The is a resizable one that stores a dynamic collection of items from the package.

Difference between and in Java

The main difference between one and one is that the length of one cannot be changed or extended. In order to add or remove items from one, we need to create a new list. On the other hand, elements can be added to or removed from the “ArrayList” at any time because they can be resized.

Converting one to one using

This is passed to this method with and an object is obtained, which in turn is passed as a parameter to the constructor of the class. The syntax of the is as follows:

Let's follow the example below.


Converting an to using

This method lists all of the elements in a given collection, much like. However, the method is much faster compared to the performance-based method. The syntax of is as follows:

Let us understand the following example.


Converting a to with

With this method we can create a new list and add the list items in a much easier way. The syntax for the method is as follows:

Let's look at the following example.


Now, if we follow the methods above, we can easily convert a to.

Related Article - Java Array

  • Check if an array contains Int in Java
  • Determine the length of a char array in Java
  • Related Article - Java ArrayList

  • Initialize ArrayList in Java