Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Java Vector 
 

Vector are array list with extended properties which follow the dynamic and automatic addition of data at run-time.

 

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 can grow and  shrink as needed to accommodate its size adding and removing items even after the Vector has been created. The Vector class implements dynamic array of objects. The Component in vector class can be accessed by integer index. Each vector tries to maintain its  storage size by capacity and a capacity Increment. The capacity of vector is always least as of  its size and usually larger because  components are added to the vector at run-time. The vector's storage get increase in chunks as the size of capacity Increment. An application increase the size of a vector before inserting a large number of components that is used to  reduce the amount of increment in reallocation. Vectors can be easily used.. It implement the Enumeration interface which makes  the contents of a Vector  traversed

Vector instances are like linked-lists that can grow dynamically. Once it reaches the maximum limit, resources are allocated dynamically and increases its size further.

How to declare Vector

Vector

The given below Syntax is used to declare an empty vector so that the size of  internal data array has 10 and its standard storage capacity has zero.

public Vector()

The given Syntax is used to construct an empty vector specified by initial capacity.

vector(int initial capacity)

The below Syntax Creates an empty vector with the specified initial capacity and capacity increment.

vector(int initial capacity,int capacity increment)

Method used in Vector

void add(int index, Object element)-  Inserts the specified element at the specified position in this Vector

.
boolean add(object o)- Appends the  specified element to the end of this Vector.


int  capacity( ) -  Return the current capacity of this vector 

void clear( )-  Removes all of the elements from this Vector.

void setsize(int new size )-Set the new size of Vector.

int size( )-Return the number of Component in Vector.

Vector trim to size( )- Trim the Capacity of Vector to vector's current size.

public int lastindexof(obj abc)-Returns the occurrence of last index of of the specified object in this vector.

Understand Vector by Example-

This java example shows us to find a maximum element of Java Vector using max method of Collections class. We Import required package, then declare a Class name maximum vector element .Inside the main method create an object of vector. The object of vector class calls add method to add the component of vector. In order to find the maximum element of vector component use, static object max(collection c) method of collection class which we already imported the Collection package .This method returns the maximum element of Java Vector.

 



import java.util.Vector;
import java.util.Collections;

public class maximum vector element

 {

 
public static void main(String[] args)

 {
   
   
//create a Vector object
   
Vector v = new Vector();
   
   
//Add elements to Vector
   
v.add(new int("500"));
    v.add
(new int("745"));
    v.add
(new int("842"));
    v.add
(new int("900"));
    v.add
(new int("567"));
   
   

   
   
Object obm = Collections.max(v);
   
    System.out.println
("Maximum Element of Java Vector is : " + obm);
 
}
}

 

Output of above code-

Maximum Element of java Vector is :900

                         

» View all related tutorials
Related Tags: java c string ide array io word vi new key this id element elements for example keyword with to ini

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

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  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

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

Copyright © 2008. All rights reserved.