Home Answers Viewqa Java-Beginners Java difference between Array and Vector

 
 


Abhilash
Java difference between Array and Vector
2 Answer(s)      5 years and 3 months ago
Posted in : Java Beginners

What is the difference between Array and Vector in Java?

View Answers

February 26, 2008 at 10:47 AM


DIFFERENCE
--------------------------
ARRAY
1.Array is unsynchronized
2.automatically increase the size when the initalized size will be exceed.

VECTOR
1.vector is synchronized.
2.when the size will be exceed at the time.vector size will increase double of initial size.

February 26, 2008 at 1:10 PM


Difference between Array & Vector

ANS1:- Array :

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.

Declaration of an array :

int arr[] = new int [10];

sometimes , may be we can define the size or not .

Another way of array declaration is :

int arr[]={ 13,34,45,56};

A simple program of using array is given below :

import java.util.*;

public class ArrayClass{
public static void main(String[] args){
int arr[] = {14,45,56,10,67};
int l = arr.length;
int i,j;
System.out.print("numbers we have given are : ");
for (i=0;i<l;i++ ){
System.out.print(" " + arr[i]);
}
System.out.println("\n");
System.out.print("Accending order number : ");
Arrays.sort(arr);
for(i=0;i<l;i++){
System.out.print(" " + arr[i]);
}
}
}

output of the above program is

10

14

45

56

67
- - - - - - - - - - - - -
Vector:

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 .

Vector class contains seven multiplemethods such as .

add(Object o): Adds the element in end of the Vector

firstElement(): Returns the first element of the vector.

elementAt(int index): Returns the element at the specified index.

size(): Gives the number of element in a vector.

removeElementAt(int index): Deletes the element from the given index

elements(): Returns an enumeration of the element

lastElement(): Returns last element.

We can also used Enumeration interface to retrieve the value from vector.

Enumeration interface has two methods.

nextElement(): Checks the next element of the enumeration.

hasMoreElements(): Checks if this enumeration contains more elements or not.

- - - - - - - - - - - - -

Array Vs Vector :

Both Array and Vector in Java are similar. Both are used for storing the data. But there are some basisc difference between Array & Vector .

1. Array is the static memory allocation , while vector is the dynamic memory allocation.

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 .

3. Vector has many more methods in comparing to Array.

4. By using Vector we can add, remove, & find the size of elements dynamically ,while it is not possible in Array.

Convert Array to Vector
http://www.roseindia.net/java/java-conversion/convert-vector-to-array.shtml











Related Pages:
what is diference between the vector and arraylist with realtime example - Java Interview Questions
what is diference between the vector and arraylist with realtime example  what is diference between the vector and arraylist with realtime example  Hi Friend, Difference between Vector and ArrayList: 1)Vector
arraylist vs vector - Java Beginners
arraylist vs vector  hi, i want to know what is the difference between arraylist and vector in case of performance. in what cases we should go for arraylist and in what case we should go for vector. is there any   array
Diff between ArrayList and Vector?
Diff between ArrayList and Vector?  What's The Difference between ArrayList and Vector Classes and Can you give me a simple Program for set and List Interface
Difference between error and exception ????????
Difference between error and exception ?  Can we handle a error in java if yes than give an code of an example? Difference between error... to access a null object or reading an array out of bounds. They can also
difference between wite and writeto in java
difference between wite and writeto in java  I am using the stream... the writeTo() method. I want to know difference between the write() and writeTo() method in java.   The writeTo() method writes the complete contents
Give difference between LinkedList and ArrayList - Java Beginners
Give difference between LinkedList and ArrayList  Hi, What is the use of LinkedList and ArrayList? How you can difference between LinkedList.../beginners/array_list_demo.shtml http://www.roseindia.net/java/beginners/linked
difference between == and === operators?
difference between == and === operators?  Is (====) operator available in java or not? difference between
difference
difference    what is the difference between the JDBC-ODBC bridge, the Native-API-Partly-Java driver, and the JDBC-Net-All-Java Driver is the placement of the database access libraries   Please visit the following link
difference
difference  difference between Method Overloading and method Overriding   Difference between Method Overloading and Method Overriding... the following links: Java Method Overloading Java Method Overriding
difference
difference  difference between thread and process in java   Difference between Process and Thread: 1)Process is a program under execution whereas Thread is a part of program. 2)Process are heavy weight programs which
Convert Array to Vector
Convert Array to Vector       In this section, you will learn to convert an Array to Vector... into a Vector. Here we have taken an array of data which gets converted to data
Convert Vector to Array
Convert Vector to Array       In this section, you will learn to convert Vector to an Array.  Code Description: This program helps you in converting Vector to an Array. Here
Difference between Timer and Thread?
Difference between Timer and Thread?  Can anyone tell me about the difference between Timer and Thread, Why we need to have Timer in case we have Thread implimentation startegy in Java
Vector in java
Vector in java Vector in java implements dynamic array. It is similar to array and the component of vector is accessed by using integer index. Size of vector can grow or shrink as needed, by adding and removing item from vector
Vector object[]
Vector object[]  I want to create payslip in java public Vector createData() { Vector result = new Vector(); Vector rec = new Vector... Olsen"}; rec.add(value); result.add(rec); rec = new Vector
difference between lock and synchronization
difference between lock and synchronization  Hi, I am new in java please anyone tell me difference between lock and synchronization in java. its urgent. Thank in advance   Please visit the following link: Lock
Java Vector
Java Vector       Vector represents a collection of similar items. In Java, the Vector class is defined in java.util package that implements a growable array of objects. Like an array
difference between hashcode,reference in java
difference between hashcode,reference in java  difference between hashcode,reference in java
what is the difference between jdk 1.4 and 1.5 and 1.6
what is the difference between jdk 1.4 and 1.5 and 1.6  what is the difference between jdk 1.4 and 1.5 and 1.6   Java 1.4 Features..., JSSE, JAAS) - Java web start Java 5.0 Features - Generics: provides compile
Vector in Java
Vector in Java are array lists that are used instead of arrays, as they have... is how to declare a Vector in Java Program: This Syntax is used to declare an empty Vector r (internal data array size-10, standard storage capacity-0): public
What is difference between the java and javascript?
What is difference between the java and javascript?  What is the difference beteen the java and javascript?   Hello Friend, Read Here Thanks
difference between applet and swings
difference between applet and swings  what are the major difference between swing and applets   Hello Friend, Differences: 1) AWT stands for Abstract windows toolkit whereas le Swing is also called as JFC?s (Java
What is the difference between mysql_fetch_object and mysql_fetch_array?
What is the difference between mysql_fetch_object and mysql_fetch_array?  What is the difference between mysqlfetchobject and mysqlfetcharray
What is the difference between a constructor and a method?
What is the difference between a constructor and a method?  Hi, What is the difference between a constructor and a method?   Hi, I have found a good link of Java program related to difference between constructor
difference between servletconfig and servletcontext in java
difference between servletconfig and servletcontext in java  difference between servletconfig and servletcontext in java   ServletContext ServletContext is implemented by the servlet container for all servlet
Java Vector
Java Vector       Introduction to Vector Vector are array list with extended properties which follow the dynamic and automatic addition of data at run-time. Unlike array, Vector
What is difference between the java and javascript?
What is difference between the java and javascript?  What is the difference beteen the java and javascript?   Hello Friend, Difference: 1) Java is a Object Oriented programming language developed by Sun Microsystems
difference between servletconfig and servletcontext in java
difference between servletconfig and servletcontext in java  ServletConfig is implemented by the servlet container to initialize a single servlet using init(). ServletContext is implemented by the servlet container for all
difference between the obj and reference - Java Beginners
difference between the obj and reference  what is the difference between object and reference ? is there any difference
What is the difference between a JDK and a JVM?
What is the difference between a JDK and a JVM?  Hi, What is the difference between a JDK and a JVM? Thanks,   Hi, JDK is stand... to compile your source files using a JVM. For more difference between JDK and JVM
Difference between object and instance? - Java Beginners
Difference between object and instance?  What is the difference between object and instance in java
difference between enum and final class?
difference between enum and final class?  what is the difference between enum and final class in java?   The java.lang.Enum is an abstract class, it is the common base class of all Java language enumeration types
what is difference between objectan primitive? - Java Beginners
what is difference between objectan primitive?  whatis difference between object and primitive
difference between java5 and java6 - Java Beginners
difference between java5 and java6  Hi, What is difference between java5 and java6 Please let me know quickly
Difference between C++ and Java - Java Interview Questions
Difference between C++ and Java  Basic difference between C... was derived from C++ but still there is big difference between these two... am going to give you few differences between these two...1. Java does not support
Difference between Java IO Class - Java Beginners
Difference between Java IO Class  What is the difference in function between Two set of Stream class as mention below- 1)FileInputStream... information. http://www.roseindia.net/java/ Thanks
Vector Iterator Java Example
Vector is a collection class.It works similar to the Array. It has... interface can traverse all its elements. Java Vector Iterator with Example import java.util.Iterator; import java.util.Vector; public class vector
Hi .Difference between two Dates - Java Beginners
Hi .Difference between two Dates  Hi Friend.... Thanks for ur Very good response.. Can u plz guide me the following Program.... difference between two dates.. I need to display the number of days by Each Month
Java : Vector Example
Java : Vector Example This segment of tutorial illustrates about the Vector class and its use with the Iterator interface. Java Vector : Vector class implements dynamic array of objects. Like array you can access its component
Difference between API and Assembly - Java Beginners
Difference between API and Assembly  Can anybody tell me what is the diffrenece between API's and assemblies?  Hi friend, Points to be remember : API *) API Stands for "Application Program Interface
Java Vector Iterator
Java Vector Iterator is a Collection class. It has similar functionality as of the Array. Its size is variable It has growable array. Its size may... all its elements. Java Vector Iterator Example import java.util.Iterator
difference
difference  difference between hashtable and hashtree
difference
difference  what's the difference between mysql and sql
Difference between sorted and ordered collection in hibernate
Difference between sorted and ordered collection in hibernate  What is difference between sorted and ordered collection in hibernate?   ... the sorting features provided by the Java collections framework. The sorting occurs
what is the difference between access specifiers and access modifiers in java?
what is the difference between access specifiers and access modifiers in java?  what is the difference between access specifiers and access modifiers in java
pls tell me the difference between the run() and start() in threads in java....
pls tell me the difference between the run() and start() in threads in java....  difference between the run() and start() in threads in java
vector question
vector question  how does vector works?   Please visit the following link: Java Vector Demo
What is the difference between an if statement and a switch statement?
What is the difference between an if statement and a switch statement?   Hi, What is the difference between an if statement and a switch statement... in Java program. http://www.roseindia.net/java/java-tips/flow/switch/switch
Difference
Difference  What Is the difference between JDK & SDK
Difference between == and equals method in java
Description: For comparing equality of string ,We Use equals() Method. There are two ways of comparison in java. One is "==" operator and another "equals()" method .  "==" compares the reference

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.