Java ArrayList Example

Ads
 

Java ArrayList Example

How can we use array list in java program ?

View Answers

June 15, 2012 at 4:11 PM

import java.util.ArrayList;


public class ArrayListExample {
    public static void main(String [] args){

     ArrayList<String> array = new ArrayList<String>();
       array.add("Amit");
       array.add("Ankit");
       array.add("Vinay");
       array.add("Deepak");
       array.add("Naulej");
       array.add("Arun"); 

    System.out.println("ArrayList Size:"+array.size());
       for(int i=0;i<array.size();i++){             
        System.out.println("ArrayList Element"+i+" :"+array.get(i));           

         }   
       }

     }

Output

ArrayList Size:6
ArrayList Element0 :Amit
ArrayList Element1 :Ankit
ArrayList Element2 :Vinay
ArrayList Element3 :Deepak
ArrayList Element4 :Naulej
ArrayList Element5 :Arun

Description:- The above program demonstrates you the use of ArrayList. An ArrayList is a data structure. It can be dynamically resized. Here, we have created an array list and store string values to it. The method size() of ArrayList class returns the size of the arraylist and get() method fetch the string values from the arraylist.

Ads









Related Tutorials/Questions & Answers:
Java ArrayList Example
Java ArrayList Example  How can we use array list in java program..."); array.add("Arun"); System.out.println("ArrayList Size...++){ System.out.println("ArrayList Element"+i+" :"+array.get(i
arraylist in java
arraylist in java  arraylist in java   Array List Example in java
Advertisements
Collection : ArrayList Example
This tutorial contains description of Collection ArrayList with example
Core Java-ArrayList
Core Java-ArrayList  How do i find duplicates in ArrayList. First i add some elements to ArrayList, then how do i find the duplicates and show the duplicate elements. Give an example
java arraylist
help how to handle this through java arraylist. xml : <?xml version='1.0...java arraylist  Hi, Thanks in advance.. From the xml given below i need to create arraylist whose name is same as type value(e.g : list1,list2
ArrayList in java
ArrayList in java  sir i have a class Student.it contains id,name,marks of students and a parameteraised constructor.now i created an arraylist... to access marks from arraylist
Collection : ArrayList Example
Collection : ArrayList Example This tutorial contains description of Collection ArrayList with example. ArrayList : For ArrayList<E> import... the element at the specified index from the Arraylist. Example : package
Java arraylist duplicate elements search
Java arraylist duplicate elements search  hi, please help me finding the no of duplicates elements in an arraylist example an arraylist contains elements like: mac raj mohan frank mac tom raj mohan frank result: mac 2 raj
arraylist
arraylist   Using arraylist class , what type of exception are throws, how can write a java programe   An ArrayList can throw ArrayIndexOutOfBoundsException. Here is a example. import java.util.*; public class
How to create new arraylist using Java
someone provides online example how to create new arraylist in java programming... arraylist Java. The Java ArrayList object is created with the reference of List...How to create new arraylist using Java  hi, I want to develop
How to convert Arraylist into String Array Java
of Java programming. Can somebody Suggest me how to convert arraylist to string array in Java. Please suggest any online example. Thanks   Hi, I... information with example. You can find the online example of how to convert arraylist
maximum size of arraylist - java
maximum size of arraylist - java  1.what is the maximum size of arraylist? 2.what is the drawback of arralist? 2.what is the drawback of JDBC? 4.how many access specifier and how many access modifier in java? 5.what
How to check if an arraylist contains a value in Java
to do this? How to check if an arraylist contains a value in Java? Thanks  ... in the given ArrayList object. Here is complete program example: package...How to check if an arraylist contains a value in Java  Hi, I have
Java programming using ArrayList Help?
Java programming using ArrayList Help?  Hi,can anybody help and guide me on doing this java program? (Largest rows and columns)Write a program that randomly fills in 0s and 1s into an n-by-n matrix,prints the matrix,and finds
Java programming using ArrayList Help?
Java programming using ArrayList Help?  Hi,can anybody help and guide me on doing this java program? (Largest rows and columns)Write a program that randomly fills in 0s and 1s into an n-by-n matrix,prints the matrix,and finds
Arraylist in java
ArrayList is a class that extends AbstractList and implements List Interface. Standard java array are of fixed length, that mean we should know the size.... but for indefinite number of elements Arraylist is used as it creates dynamic Array
How to sort ArrayList in java
How to sort ArrayList in java In this section you will learn how to sort ArrayList in java. ArrayList support dynamic array that can grow as needed. Array... which sort the Arraylist. Now here is the code to sort the ArrayList in java
arraylist
arraylist  Hi how can we eliminet duplicate element from arraylist in java? how can we achieve data abstrcation and encapulation in java? how many type of modifier are there in java? Thanks kalins anik   Remove
arraylist
in arraylist, then how can i find out all infomation of class A using emplyee id . Thanks kalins Naik   Here is an example that stores employee data into an arraylist and display the data of the particular employee according
Array list in Java - arraylist type error
Array list in Java - arraylist type error  I am using Array list in Java but when i compile i get array list type error. Can anyone please explain what is array list type error and why it occurs
ArrayList
ArrayList  import java.util.*; class ArrayListDemo2 { public static void main(String args[]) { ArrayList al=new ArrayList(); al.add("one"); al.add("two"); al.add("three"); al.add("four"); for(int i=0;i Expected
arraylist
arraylist  Hi How can we eliminet duplicate element from arraylist? How can we find highest salary from arraylist ? How can we highest key value pair from map? Thanks Kalins Naik   Remove duplicates from Arraylist
arraylist
% *(noOfYearService/2). Store each employee information in different arrayList depending on his
Retrieve all the students in the same year(Java ArrayList)?
Retrieve all the students in the same year(Java ArrayList)?  FoundStudents.jsp year- parameter I receive from a form search- is an object of type... = search the ArrayList students starting from this index, not from the beginning
arraylist of an arraylist
arraylist of an arraylist  Can anyone suggest me how to use arraylist of an arraylist?? how to put data into it and get data from it???? becoz i want to make rows and column dynamic which can grow as per requirement?????/ plz
java persistence example
java persistence example  java persistence example
Java Client Application example
Java Client Application example  Java Client Application example
Any Link Between ArrayList and HashMap - Java Interview Questions
Any Link Between ArrayList and HashMap  Hi Friends, Can u give few interview questions which relates ArrayList and Hashmap. I mean how to link ArrayList and HashMap. Thanks Prakash  Hi Friend, Similarities: 1
Example of HashSet class in java
Example of HashSet class in java. In this part of tutorial, we... unique. You can not store duplicate value. Java hashset example. How.... Example of Hashset iterator method in java. Example of Hashset size() method
What is array in java with example?
What is array in java with example?  Hi, I am beginner in Java and want to learn Java Array concepts. Which is the best tutorials for learn Java Array with example codes? What is array in java with example? Thanks
Example of HashMap class in java
Example of HashMap class in java. The HashMap is a class in java collection framwork. It stores values in the form of key/value pair. It is not synchronized

Ads