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,
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 myCollection’s Iterator.
Hi
This is a very helpfull website.Please cover Threads also.
Regards
asha
its Correct ..100% useful
fine asha.
i’ll put some exmples on threads
nice site
This is very helpful. Is it possible to show an example of the write/read methods?
it is very useful.please give many programs.
This content is help and serves better for any beginner to collections framework
Thanks for the great programs and annotation. It really helps.
Please give some examples for xml parsing
This is really a wonderful website.It’s help me great for my preparation.
Regards,
CT.Srinivaasan.
sir this webside is very very usefull sir thank you
hiee first of all We would like to thank you for ur excellent work in making this website. This is the best website which i have seen where each and every topic is covered clearly with a lot of examples. please cover exceptions concept also, we couldn’t get it from any textbook, the approach is not clear. we are working in MNC. We need it as early as possible. Hope u wil consider it soon.
Thanks alot… :))
with regards,
JRC
i find this is useful stuff for java beginer……
hi everybody,
this is really a very helpful site.
u know how to use stringbuilder to concate words into a paragraph and have space between .
simple and useful website
simple and useful….
i liked the way u explain examples.This is the one which i was searching.Thanks.
·
Question 3 / 4 (ATM Cash Machine)
You are to write a program for a
bank ATM machine. The machine dispenses notes as as well as coins, in the
standard Indian denominations: 1, 2, 5, 10, 20, 50, 100, 500, 1000. Your
program takes the amount to be withdrawn as the input. As output, it should
output (to standard output) the breakup of that amount into the denominations
above, using the FEWEST POSSIBLE NUMBER of notes and coins, in the text format
specified below. The solution template has some code written already, as a
possible starting point for the solution. You may use this or you may choose
not to, the choice is yours!
Here are the test cases your program
should pass. Note that each line of the output should be: a number, followed by
a space, followed by the character “x”, followed by another space,
and then another number.
1. Input:
4177
Output:
4x 1000
1x 100
1x 50
1x 20
1x 5
1x 2
2. Input:
9999
Output:
9x 1000
1x 500
4x 100
1x 50
2x 20
1x 5
2x 2
3. Input:
50
Output:
1 x 50
please help me to solve it……
what is the two ways to iterate the elements of a collection with program
Who is the author of this?i really thankful to him/her.so useful
pls make a program that will input a name ang seat no.in 2 dimensional array
tnx..asap
Great