Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
471 views

ArrayList - Java Examples - Java Program Sample Source Code

ArrayList is a resizable array which implements list interface. ArrayList uses an array to store its elements. It grows automatically as we add elements to it. Every time this happens, the internal array has to be reallocated.

Uploaded by

Akhil Singh
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
471 views

ArrayList - Java Examples - Java Program Sample Source Code

ArrayList is a resizable array which implements list interface. ArrayList uses an array to store its elements. It grows automatically as we add elements to it. Every time this happens, the internal array has to be reallocated.

Uploaded by

Akhil Singh
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ArrayList | Java Examples - Java Program Sample Source Code

http://www.java-examples.com/arraylist

HOME

JAVA FUNDAMENTALS

COMMON CLASSES

JAVA.LANG

FILE AND IO

COLLECTIONS

FREE IT BOOKS

SUBMIT EXAMPLE

Home Java Collections And Data Structures ( java.util package ) ArrayList

Are You a Fresher?


Join IT Diploma Programs & Get Job-Ready in 99 Days. Apply Now!
NIITEducation.com/99days/Jobs

Latest Hair Styles 2011


Save Up To 90% on Trendy Hair Cuts. Register Now to Avail This Offer!
Snapdeal.com/HairSalons+Offers

Virtual Server Rs.2100/cPanel/ Plesk with Full Root Access @ 99.95 Uptime SLA. Check Offers
Ctrls.com/VPS-Hosting-Servers-India

Java String array


Java String array examples and the Java 5 for loop syntax (free).
devdaily.com

Search Java Examp

View daily updated mobile price lists, Search lowest price of any mobile phone at Mobile Price India.

ArrayList
Java ArrayList is a resizable array which implements List interface. ArrayList provides all operation defined by List interface. Internally ArrayList uses an array to store its elements. ArrayList provides additional methods to manipulate the array that actually stores the elements. ArrayList is equivalent to Vector, but ArrayList is not synchronized. Java ArrayList Capacity Capacity of an ArrayList is the size of the array used to store the list elements. It grows automatically as we add elements to it. Every time this happens, the internal array has to be reallocated. This increases the load. We can set the initial capacity of the ArrayList using following method. ArrayList arrayList = new ArrayList(); arrayList.ensureCapacity(100); Java ArrayList Iterators Java ArrayList provides two types of Iterators. 1) Iterator 2) ListIterator Iterator iterator = arrayList.iterator(); Returns object of Iterator. ListIterator listIterator = arrayList.listIterator(); Returns object of ListIterator. ListIterator listIterator = arrayList.listIterator(int startIndex); Returns object of ListIterator. The first next() method call on this ListIterator object will return the element at the specified index passed to get the ListIterator object. Iterators returned by these methods are fail-fast. That means if the list is modified after getting the Iterator by using some other means rather than Iterators own add or remove method, Iterator will throw ConcurrentModificationException. ArrayList Constructors 1) ArrayList() Creates an empty ArrayList. For example, ArrayList arrayList = new ArrayList(); 2) ArrayList(int capacity) Creates an ArrayList with specified initial capacity. For example, Get your FREE copy

Get FREE Oracle Magazine

Contains technology strate articles, sample code, tips and partner news, how to for developers and DBAs, more.

1 of 3

09-10-2011 23:25

ArrayList | Java Examples - Java Program Sample Source Code

http://www.java-examples.com/arraylist

ArrayList arrayList = new ArrayList(10); 3) ArrayList(Collection c) Creates an ArrayList containing elements of the collection specified. For example, ArrayList arrayList = new ArrayList(myCollection); Where myCollection is an object of the type Collection. This creates an ArrayList of elements contained in the myCollection, in the order returned by the myCollections Iterator. Java ArrayList Examples

Add an element to specified index of Java ArrayList Example Append all elements of other Collection to Java ArrayList Example Copy all elements of Java ArrayList to an Object Array Example Get Size of Java ArrayList and loop through elements Example Get Sub List of Java ArrayList Example Insert all elements of other Collection to Specified Index of Java ArrayList Example Iterate through elements Java ArrayList using Iterator Example Iterate through elements Java ArrayList using ListIterator Example Remove all elements from Java ArrayList Example Remove an element from specified index of Java ArrayList Example Replace an element at specified index of Java ArrayList Example Search an element of Java ArrayList Example Simple Java ArrayList Example Sort elements of Java ArrayList Example

Related Java Examples


Arrays Collections Comparator Enumeration Hashmap HashSet Hashtable Iterator LinkedHashMap LinkedHashSet LinkedList ListIterator Searching Sorting TreeMap TreeSet Vector

Add new comment

Email this page

Helpfull!!!
Submitted by Anonymous on Thu, 04/02/2009 - 04:00.

Hi This is a very helpfull website.Please cover Threads also. Regards asha


reply

Read & Write method


Submitted by Anonymous on Sun, 04/05/2009 - 22:32.

This is very helpful. Is it possible to show an example of the write/read methods?


reply

helpful
Submitted by Anonymous on Thu, 08/13/2009 - 12:22.

it is very useful.please give many programs.


reply

Better way
Submitted by Anonymous on Sat, 09/05/2009 - 12:12.

This content is help and serves better for any beginner to collections framework
reply

2 of 3

09-10-2011 23:25

ArrayList | Java Examples - Java Program Sample Source Code

http://www.java-examples.com/arraylist

making progress
Submitted by Anonymous on Thu, 09/24/2009 - 20:15.

Thanks for the great programs and annotation. It really helps.


reply

Superb
Submitted by Anonymous on Wed, 10/28/2009 - 13:55.

Please give some examples for xml parsing


reply

This is really a wonderful


Submitted by Anonymous on Tue, 06/08/2010 - 10:32.

This is really a wonderful website.It's help me great for my preparation. Regards, CT.Srinivaasan.
reply

Recent Popular Examples


Java String Split Example Java Interface example Calculate Circle Area using Java Example Iterate through the values of Java HashMap example Sort elements of Java ArrayList Example

All-time Popular Examples


Java String Split Example Iterate through the values of Java HashMap example Java Interface example Read file using FileInputStream Sort elements of Java ArrayList Example
Privacy Policy. Copyright 2005-2009 Java Examples.

3 of 3

09-10-2011 23:25

You might also like