<?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; Define Vector</title>
	<atom:link href="http://www.bestjavainterviewquestions.com/category/java-util-questions/define-vector/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, 03 Feb 2012 10:23:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Write a Short notes on Vectors</title>
		<link>http://www.bestjavainterviewquestions.com/write-a-short-notes-on-vectors/</link>
		<comments>http://www.bestjavainterviewquestions.com/write-a-short-notes-on-vectors/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 13:22:30 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Define Vector]]></category>
		<category><![CDATA[define vector class]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=424</guid>
		<description><![CDATA[VECTORS C and C++ programmers will know that generic utility functions with variable arguments can be used to pass different arguments depending upon the calling situations. Java does not support the concept of variable arguments to a function. This feature can be achieved in Java through the use of the Vector class contained in the [...]]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration: underline;"><strong>VECTORS</strong></span></p>
<p>C and C++ programmers will know that generic utility functions with variable arguments can be used to pass different arguments depending upon the calling situations. Java does not support the concept of variable arguments to a function. This feature can be achieved in Java through the use of the Vector class contained in the <strong>java.util </strong>package. This class can be used to create a generic dynamic array known as Vector that can hold <em>objects of any type</em> and any <em>number</em>. The objects do not have to have to be homogenous. Array can be easily implemented as vector. Vectors are created like arrays as follows:</p>
<p><strong>Vector</strong> intVect  = new Vector();   //declaring without size</p>
<p><strong>Vector </strong>list        = new Vector(3);  // declaring with size.</p>
<p>Note that a vector can be declared without specifying any size explicitly. A vector can accommodate an unknown number of items. Even, when a size is specified, this can be overlooked and different number of items may be put into the vector. Remember, in contrast, an array must always have its size specified.</p>
<p>Vector possess a number of advantages over arrays.</p>
<p>1.  It is convenient to use vectors to store objects.</p>
<p>2. A vector can be used to store alist of objects that may vary in size.</p>
<p>3.  We can add and delete objects from the list as and when required.</p>
<p>A major constraint in using vectors is that we cannot directly store simple data types in a vector; we can only store objects. Therefore, we need to convert simple tyhpes to objects. This can be done using the wrapper classes.</p>
<p>The vector class supports a number of methods that can be used to manipulate the vectors created. Important ones are listed</p>
<p><span style="text-decoration: underline;"><strong>Method Call</strong></span><strong> </strong><strong> </strong><strong>and <span style="text-decoration: underline;">task performed</span><br />
</strong></p>
<p><em>list.addElement (item) </em> Adds the item specified to the list at the end.</p>
<p><em>list.elementAt(10) </em>Gives the name of the 10th object.</p>
<p><em>list.size()</em> Gives the number of objects present.</p>
<p><em>list.removeElement(item) </em>Removes the specified item from the list.</p>
<p><em>list.removeElementAt(n) </em>Removes the item stored in the n<em>th</em> position of the list.</p>
<p><em>list.removeAllElements() </em> Removes all the item stored in the n<em>th</em> position of the list.</p>
<p><em>list.copyInto(array) </em> Copies all items from list to array.</p>
<p><em>list.insertElementAt(item,n) </em> Inserts the item at n<em>th</em> position.</p>
<p><strong>Example of working with vectors:</strong></p>
<p>import java.util.*;</p>
<p>class LanguageVector<br />
{<br />
public static void main(String args[])<br />
{<br />
Vector list=new Vector();  //creating an object for vector class<br />
int length=args.length;</p>
<p>for(int i=0;i&lt;length;i++)<br />
{<br />
list.addElement(args[i]);;<br />
list.insertElementAt(&#8220;COBOL&#8221;,2);<br />
int size=list.size();<br />
String listArray[]=new String[size];<br />
list.copyInto(listArray);<br />
System.out.println(&#8220;List of Languages&#8221;);</p>
<p>for(int i=0;i&lt;size;i++)<br />
{<br />
System.out.println(listArray[i]);<br />
}<br />
}<br />
}</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>June 23, 2008 -- <a href="http://www.bestjavainterviewquestions.com/19/" title="Java Basic Questions">Java Basic Questions</a> (1)</li><li>September 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/what-is-default-package-in-java/" title="What is Default Package in Java">What is Default Package in Java</a> (0)</li><li>September 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/mapping-files-in-hibernate/" title="Mapping Files in Hibernate">Mapping Files in Hibernate</a> (0)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/basic-java-interview-question/" title="Basic Java Interview Question">Basic Java Interview Question</a> (1)</li><li>May 22, 2008 -- <a href="http://www.bestjavainterviewquestions.com/basic-java-interview-questions-on-lang-package/" title="Basic Java Interview Questions on lang package">Basic Java Interview Questions on lang package</a> (2)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/write-a-short-notes-on-vectors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

