Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java ArrayList Example
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Naulej kumar
Java ArrayList Example
1 Answer(s)      2 years and 4 months ago
Posted in : Java Beginners


How can we use array list in java program ?


Advertisement
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.



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
Java ArrayList
Java ArrayList   How to declare unique ArrayList
Java arraylist generics example and arraylist generic list
data type element. Example of Java Generic Arraylist import... feature of java 5. When the ArrayList is generalized for a specific data... static void main(String[] args) {       List list=new ArrayList
what is diference between the vector and arraylist with realtime example - Java Interview Questions
what is diference between the vector and arraylist with realtime example  what is diference between the vector and arraylist with realtime example  Hi Friend, Difference between Vector and ArrayList: 1)Vector
Java arraylist of arraylist
Java arrayList can make the use of other arrayList.  In one arrayList other arrayList can be added as the object  It works as two dimension array. Example of Java Arraylist of Arraylist import
Example for when to use ArrayList and when to use HashMap - Java Interview Questions
Example for when to use ArrayList and when to use HashMap  Hi Deepak u have replied this answer for when to use arraylist and hashmap " When your... example for this "once objects stored using arraylist ow to retrieve that using
Collection : ArrayList Example
This tutorial contains description of Collection ArrayList with 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
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, linkedlist
Java arraylist, linkedlist  What is the major difference between LinkedList and ArrayList
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
Iterate java Arraylist
of the ArrayList can be traversed by the Iterator. Iterator has methods hasNext() and next(). Example of Java Arraylist Iterate import java.util.*; public class... Iterator is an interface in the collection framework. ArrayList
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
Java arraylist iterator
ArrayList has iterator() method.Using iterator() method  elements of the arraylist easily gets retrieved. iterator() can be used in the for loop. It is clear by the given example. Example of Java Arraylist
Java arraylist index() Function
Java arrayList has index for each added element. This index starts from 0. arrayList values can be retrieved by the get(index) method. Example of Java Arraylist Index() Function import
ARRAYLIST CODE - Java Beginners
ARRAYLIST CODE  HELLO SIR,I AM VERY NEW TO JAVA FIELD,HOW TO READ ELEMENTS FROM TWO ARRAYLIST AND PRINT THE ELEMENTS WHICH ARE COMMON TO TWO ARRAYLIST IN ONE LINE AND OTHER IN NEXT LINE,PLZ HELP ME.IN ADVANCE THANK U VERY
Java new arraylist
Java ArrayList object is created with the reference of List interface Object is also created directly by the ArrayList class Java New Arraylist Example import java.util.*; public class List1 { public static void
Java ArrayList sublist
It returns the part of the ArrayList as List reference. part is the given range between two indexes. Java Arraylist Sublist Example import...) { String  ar[]={"india","pakistan","United Kingdom","Japan","Korea"}; ArrayList
Java ArrayList clone
It returns the copy of the given ArrayList object as the Object class. So it must be casted to the ArrayList for further use. Java Arraylist Clone Example import java.util.*; public class List1 { public static
Java ArrayList removeall
the elements from list1 which is present in the list2 Java Arraylist Removeall Example import java.util.*; public class List1 { public static void...","Korea"}; ArrayList list=new ArrayList(); ArrayList list1=new ArrayList
Java arraylist for loop
Elements of the ArrayList can be easily added and retrieved by the for loop. Example FOR Java arraylist for loop import java.util.ArrayList...(String[] args) {         List list=new ArrayList();         String names
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 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
arraylist - Java Beginners
arraylist  Hi.. I've an arraylist where i need to add a string array along with other string values. My string array is array[] and arraylist is al i added other string values name,time,date as al.add(name); al.add(time
arraylist problem - Java Beginners
arraylist problem  Hello.... I wrote the following code for adding a string array into an array list along with other strings... and to display...{ ArrayList al = new ArrayList(); for(int i=0;i<10;i++){ String event
Java arraylist merge
is joined in to the list1. Example Java Arraylist Merge import... In Java Two arrays can be joined by using the Collection list...};         List list1=new ArrayList();         List list2=new ArrayList
arrayList - Java Beginners
must check through the desktop arraylist and notebook arraylist. How can I combine this two arraylist checking for throw out the msg of "Computer list is empty!" Currently I only can check for desktop arraylist empty if no desktop is added
arraylist declaration in java
of the List interface Example of Java Arraylist Declaration import... void main(String[] args) {         List list=new ArrayList();         String
 

 

 

DMCA.com