<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Java Interview Questions &#187; ArrayList Class</title>
	<atom:link href="http://www.bestjavainterviewquestions.com/category/java-util-questions/arraylist-class/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bestjavainterviewquestions.com</link>
	<description>Java Interview Questions &#124; Core Java Interview Questions &#124; Advanced Java Interview Questions &#124; EJB Interview Questions &#124; J2EE Interview Questions &#124; Hibernate Interview Questions</description>
	<lastBuildDate>Fri, 30 Jul 2010 06:00:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>ArrayList Class</title>
		<link>http://www.bestjavainterviewquestions.com/arraylist-class/</link>
		<comments>http://www.bestjavainterviewquestions.com/arraylist-class/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 16:38:17 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[ArrayList Class]]></category>
		<category><![CDATA[define arraylist]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=426</guid>
		<description><![CDATA[The ArrayList class extends AbstractList and implements the List interface. ArrayList supports dynamic arrays that can grow as needed. In Java, standard arrays are of a fixed length. After arrays are created, they cannot grow or shrink, which means that you may not know util run time precisely how large of an array you need. [...]]]></description>
			<content:encoded><![CDATA[<p>The <strong>ArrayList</strong> class extends <strong>AbstractList</strong> and implements the <strong>List </strong>interface. <strong>ArrayList</strong> supports dynamic arrays that can grow as needed. In Java, standard arrays are of a fixed length. After arrays are created, they cannot grow or shrink, which means that you may not know util run time precisely how large of an array you need. To handle this situation, the collections framework defines ArrayList.</p>
<p>In essence, an ArrayList is a variable-length array of object references. Thjat is, an <strong>ArrayList </strong>can dynamically increase or decrease in size. Array lists are created with an initial size. When this size is exceeded, the collection is automatically enlarged. When objects are removed, the arraya may be shrunk.</p>
<p>It is dynamically growing array that stores objects. It is not Synchronized and Vector is a Synchronized</p>
<p><strong>Note: </strong>You can&#8217;t store primitive data type. we can store only object into ArrayList.</p>
<p><strong>ArrayList</strong> has the constructors shown here:</p>
<p><strong>&#8211;&gt; </strong>ArrayList();  <em>//This constructor builds an empty array list</em></p>
<p><strong>&#8211;&gt; </strong>ArrayList(Collection c)  <em>// This constructor builds an array list that is initialized with the elements of collection <strong>c</strong>.</em></p>
<p><strong>&#8211;&gt; </strong>ArrayList(int <em>capacity</em>)  <em>//This Contructor builds an array list that has the specified initial capacity.</em></p>
<p><em>1) To Creat  an ArrayList</em></p>
<p>ArrayList arl=new ArrayList();  //creating an object</p>
<p>ArrayList Arl=new ArrayList(20);  //creating an object with the size</p>
<p><em>2) To add objects use add() method</em></p>
<p>arl.add(&#8220;APPLE&#8221;);</p>
<p>arl.add(2,&#8221;APPLE&#8221;);</p>
<p><em>3) To Remove objects use remove().</em></p>
<p>arl.remove(&#8220;APPLE&#8221;);  //remove an string</p>
<p>arl.remove(2);  //removing the string  of specified location</p>
<p><em>4) To Know Number of objects, use size()</em></p>
<p>int n= arl.size()   // It displays the size of the array list.</p>
<p><strong>Example of using an ArrayList.</strong></p>
<p>//Demonstrating ArrayList.</p>
<p>import java.util.*;</p>
<p>class Arraylist Demo  {<br />
public static void main(String args[])  {</p>
<p>ArrayList list=new ArrayList();  //creating an object for ArrayList class<br />
System.out.println(&#8220;Initial size of al:&#8221;+al.size());</p>
<p>//add  elements to the array list<br />
al.add(&#8220;C&#8221;);<br />
al.add(&#8220;B&#8221;);<br />
al.add(&#8220;A&#8221;);<br />
al.add(&#8220;D&#8221;);<br />
al.add(&#8220;E&#8221;);<br />
al.add(&#8220;T&#8221;);<br />
al.add(1,&#8221;A2&#8243;);</p>
<p>System.out.println(&#8220;Size of al after additions: &#8220;+ al.size());</p>
<p>//display the array list<br />
System.out.println(&#8220;Content of al:&#8221;+al);</p>
<p>//Remove elements from the array list<br />
al.remove(&#8220;F&#8221;);<br />
al.remove(2);</p>
<p>System.out.println(&#8220;size of al after deletion:&#8221; +al.size());<br />
System.out.println(&#8220;contents of al:&#8221;+al);<br />
}<br />
}</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/java-basics-interview-questions/" title="Java Basics Interview Questions"><img src="Array" alt="Java Basics Interview Questions" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/goto-statement-in-java/" title="GoTo statement in Java"><img src="Array" alt="GoTo statement in Java" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/define-session-hijacking-3/" title="Define Session Hijacking"><img src="Array" alt="Define Session Hijacking" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/basic-java-interview-questions-on-lang-package/" title="Basic Java Interview Questions on lang package"><img src="Array" alt="Basic Java Interview Questions on lang package" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/define-servletinputstream/" title="Define ServletInputStream"><img src="Array" alt="Define ServletInputStream" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/arraylist-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
