Basic example of array List in java
#java #array #arrayList #javaArray
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.
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");
do
{
String str=kb.next();
if(str.equals("quit"))
break;
myfriends.add(str);
}while(true);
for(String name:myfriends)
System.out.println(name);
}
}
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 .