Java Vector

Vectors are used instead of arrays because unlike array they can adjust according to the component added or removed from them.


How to convert String Date to Timestamp in Java? Best Java Tutorial for Beginners Read user input in Java using Scanner Java Programming Examples Read file line by line in Java 8 What are the benefits of learning Java Programming? A brief history and future of Java programming language Importance of Java for Mobile Application Development How To Become A Good Software Developer? Learn Java Programming for beginners 5 Reasons Java is Still a Great Language to Boost Your Career Prospect as a Programmer How to learn Java with no programming experience? How to learn Java? What are Classes and Interfaces in Java? Converting a String to Integer in Java How to check if a string exists in a string in JavaScript? Installing JDK 8 on Windows 10 and configuring the settings Video Tutorial of reading file in Java 9 Invincible Reasons to learn Java New to Java programming Java Programming Tips, Articles and Notes How to download JDK 1.6? Encapsulation in Java Programming How to format number in Java? Generics Example Program in Java Java 9 Features Java 9 Tutorial, news and examples How to read content of JPEG file in Java? Image Processing Tutorials in Java Programming Language Introduction to Java Technology Java 8 Consumer Interface with forEach Loop Introduction to Generics in Java Java 8 consumer class(interface) example Oracle Launches Project Valhalla for Java How to read properties file in Java? How to add JDK 8 support in Eclipse? Java 8: Java 8 is officially released and it can be downloaded How to Invoke method using Reflection API of Java? First Lambda Expressions in Java Java 8 expected release date

Vectors in Java are used because they can expand whenever a new data is added to them. They also shrink when data is removed from them. The Vector class implements dynamic array of objects.

Vectors can only hold objects. Components are added to Vector during runtime.

Items can be removed even after the Vector has been created.

Vectors are array list with extended properties which follow the dynamic and automatic addition of data at run-time. The Component in vector class can be accessed by integer index.

Capacity of vector is usually larger as components are added in it during run time.

Size of vectors increases in chunks.

Vector instances are like linked-lists, whenever they reach maximum limit, resources are allocated dynamically and its size is increased further.

To create a Vector import java.util.Vector or java.util.*

How to declare Vector

Following Syntax is used to declare an empty vector so that its standard storage capacity is zero

public Vector()

Following Syntax constructs an empty vector specified by initial capacity:

vector(int initial capacity)

Following Syntax creates an empty vector with the specified initial capacity and capacity increment:

vector(int initial capacity,int capacity increment)

Method used in Vector

Following method inserts the specified element at the specified position in the Vector:

void add(int index, Object element)

Following method appends the specified element to the end of the Vector:

boolean add(object o)

Following method return the current capacity of the vector:

int capacity( )

Following method removes all of the elements from the Vector:

void clear( )

Following method sets the new size of Vector

void setsize(int new size )

Following method returns the number of Component in Vector:

int size( )

Following method trims the Capacity of Vector to vector's current size:

Vector trim to size( )

Following method returns the occurrence of last index of the specified object in the vector:

public int lastindexof(obj abc)

Following is the Example 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);


Maximum Element of java Vector is :900


Share on Google+Share on Google+

Java Vector

Posted on: October 2, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Java Vector  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image