Go Back

Basic example of array List in java

All Articles

#java #array #arrayList #javaArray

Basic example of array List in java

Basic example of array List in java 

 The ArrayList class is a resizable array, which can be found in the java.util package.
 ArrayList is implementation of the List interface. It implements all optional list operations, and permits all elements, including null.

more detail click here

Property of  ArrayList 

  1. A resizable array: implementing the List interface,
  2. Mutable: objects can be added and/or removed,
  3. Not Thread-safe: ArrayList is not suitable for concurrent access. See Thread Safety for more informatio .

How to create an ArrayList
How to iterate  ArrayList ?
let's see the basic example of array list ,here I created class FriendsList , 
Input is taken via command line interface and then in program it is printing 
total number of element in Array List .


import java.util.*;
class FriendsList
public static void main(String [ ] args)
Scanner kb=new Scanner(System.in);
ArrayList myfriends=new ArrayList();
System.out.println("enter names of persons and type quit to stop");
String str=kb.next();

for(String name:myfriends)


Here we learn how to  create an ArrayList.

we see  details of iterating  ArrayList and printing element.

Hope you like it subscribe our instagram and facebook account for more update .