How To Use Arraylist In Java With Example ?.

ArrayList is a simple Collection which is provided by the Java Collection Framework API. The class ArrayList is dynamic implementation of an array. ArrayList is like an array which can grow dynamically.
Program to demonstrate how to implement ArrayList class in java.util.* ; package along with its operations :
package com.hubberspot.collections.example ;

import java.util.* ;

public class ArrayListExample
{
public static void main(String args [ ])
{
ArrayList list = new ArrayList() ;

System.out.println( " Initial size of list : " +
" " + list.size( )) ;

list.add( " A " ) ;
list.add( " B " ) ;

/> list.add( " C " ) ;
list.add( " D " ) ;
list.add( " E " ) ;
list.add( " F "

) ;
list.add( 1 , " 1 " ) ;

System.out.println( " Size after addition : " +
" " + list.size( ));

System.out.println( " Contents of list : " + list ) ;

for( Object str : list ) {
System.out.println( str ) ;
}

list.remove( " F " ) ;
list.remove( 2 ) ;

System.out.println( " Size of after deletion : "
+ list.size( )) ;
System.out.println( " Contents of list : " + list ) ;
}
}


 


For more of such hot topics read my other posts here :

Visit my new website



Article Written By jontymagicman

I am DInesh Varyani.

Last updated on 29-07-2016 277 0

Please login to comment on this post.
There are no comments yet.
How To Create A Simple Frame Using Swing Api In Java?.
How To Perform Operations Of Union And Intersection On Two Or More Linkedlist In Java ?.