Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

Fresher Job


 

Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

Tutorials

Java Server Pages

JAXB

Java Beans

JDBC

MySQL

Java Servlets

Struts

Bioinformatics

Java Code Examples

Interview Questions

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting

Linux

Beginner Guide to Linux Server

Frameworks

Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers

Softwares

Adware & Spyware Remover

Open Source Softwares

Java difference between Array and Vector
Expert:Abhilash
<p>What is the difference between Array and Vector in Java?</p>
Answers
DIFFERENCE<br />--------------------------<br />ARRAY<br />1.Array is unsynchronized <br />2.automatically increase the size when the initalized size will be exceed.<br /><br />VECTOR<br />1.vector is synchronized.<br />2.when the size will be exceed at the time.vector size will increase double of initial size.
Difference between Array &amp; Vector<br /><br />ANS1:- Array :<br /><br />Array is most important thing in any programming language .Array is used to store the data items of the same kind .It means in array we can store the multiple values of same datatype belonging to a particular class. Array stores the values in memory at the fixed size. Multiple types of arrays are used in any programming language such as: one - dimensional, two - dimensional or can say multi - dimensional. <br /><br />Declaration of an array :<br /><br />int arr[] = new int [10];<br /><br />sometimes , may be we can define the size or not .<br /><br />Another way of array declaration is :<br /><br />int arr[]={ 13,34,45,56}; <br /><br />A simple program of using array is given below :<br /><br />import java.util.*;<br /><br />public class ArrayClass{<br /> public static void main(String[] args){<br /> int arr[] = {14,45,56,10,67};<br /> int l = arr.length;<br /> int i,j;<br /> System.out.print(&quot;numbers we have given are : &quot;);<br /> for (i=0;i&lt;l;i++ ){<br /> System.out.print(&quot; &quot; + arr[i]);<br /> }<br /> System.out.println(&quot;\n&quot;);<br /> System.out.print(&quot;Accending order number : &quot;);<br /> Arrays.sort(arr);<br /> for(i=0;i&lt;l;i++){<br /> System.out.print(&quot; &quot; + arr[i]);<br /> }<br /> }<br />}<br /><br />output of the above program is<br /><br />10<br /><br />14<br /><br />45<br /><br />56<br /><br />67<br />- - - - - - - - - - - - -<br />Vector:<br /><br />For using vector we have to include java.util.Vector class. We create an object of Vector class and performs various operation like adding, removing etc. Vector class extends AbstractList and implements List, RandomAccess, Serializable interfaces . The size of a vector increase and decrease according to the program requirement .<br /><br />Vector class contains seven multiplemethods such as .<br /><br />add(Object o): Adds the element in end of the Vector<br /><br />firstElement(): Returns the first element of the vector.<br /><br />elementAt(int index): Returns the element at the specified index.<br /><br />size(): Gives the number of element in a vector.<br /><br />removeElementAt(int index): Deletes the element from the given index<br /><br />elements(): Returns an enumeration of the element<br /><br />lastElement(): Returns last element.<br /><br />We can also used Enumeration interface to retrieve the value from vector.<br /><br />Enumeration interface has two methods.<br /><br />nextElement(): Checks the next element of the enumeration.<br /><br />hasMoreElements(): Checks if this enumeration contains more elements or not.<br /><br />- - - - - - - - - - - - -<br /> <br />Array Vs Vector :<br /><br />Both Array and Vector in Java are similar. Both are used for storing the data. But there are some basisc difference between Array &amp; Vector .<br /><br /> 1. Array is the static memory allocation , while vector is the dynamic memory allocation.<br /><br />2. Array allocates the memory for the fixed size ,in array there is wastage of memory, while Vector allocates the memory dynamically means according to the requirement no wastage of memory .<br /><br />3. Vector has many more methods in comparing to Array.<br /><br />4. By using Vector we can add, remove, &amp; find the size of elements dynamically ,while it is not possible in Array. <br /><br />Convert Array to Vector<br /><a href="http://www.roseindia.net/java/java-conversion/convert-vector-to-array.shtml"; target="_blank">http://www.roseindia.net/java/java-conversion/convert-vector-to-array.shtml</a><br /><br /><br /><br />
More Questions
Post Answers
 
Ask Question Facing Programming Problem?
Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.