This website includes Education Information like a programming language, job interview question, general knowledge.mathematics

Education log

PageNavi Results No.

Ads

Monday, February 20, 2023

java array list example

 java array list example


In this tutorial, we will learn about the ArrayList class in Java. We will learn about different operations and methods of the arraylist with the help of examples.


In Java, we use the ArrayList class to implement the functionality of resizable-arrays.


It implements the List interface of the collections framework.



Java ArrayList class uses a dynamic array for storing the elements. It is like an array, but there is no size limit. We can add or remove elements anytime. So, it is much more flexible than the traditional array. It is found in the java.util package. It is like the Vector in C++.



Example java Arraylist:


import java.util.*;  

 public class ArrayListExample1{  

 public static void main(String args[]){  

  ArrayList<String> list=new ArrayList<String>();//Creating arraylist    

      list.add("Mango");//Adding object in arraylist    

      list.add("Apple");    

      list.add("Banana");    

      list.add("Grapes");    

      //Printing the arraylist object   

      System.out.println(list);  

 }  

}  


No comments:

Post a Comment