Share on Google+Share on Google+

core Java Collections
1 Answer(s)      7 years ago
Posted in : Java Beginners


View Answers

September 14, 2009 at 1:52 PM

Hi Friend,

The Vector implements a growable array of objects. It contains components that can be accessed using an integer index like an array. The size of a Vector can grow or shrink as needed to accommodate adding and removing items in vector.


import java.util.*;
public class VectorDemo{
public static void main(String[] args){
Vector<Object> vector = new Vector<Object>();
int primitiveType = 10;
Integer wrapperType = new Integer(20);
String str = "tapan joshi";
vector.add(2, new Integer(30));
System.out.println("the elements of vector: " + vector);
System.out.println("The size of vector are: " + vector.size());
System.out.println("The elements at position 2 is: " + vector.elementAt(2));
System.out.println("The first element of vector is: " + vector.firstElement());
System.out.println("The last element of vector is: " + vector.lastElement());
Enumeration e=vector.elements();
System.out.println("The elements of vector: " + vector);
System.out.println("The elements are: " + e.nextElement());

Difference between Array and Vector:

1.Vector is implemented from List interface where as array is a primitive
2.The size of a vector can be changed dynamically where as size is fixed in array.
3.Vector is Synchronized where as array is not
4.Vector can store only object references where as Array can store primitive data type.


Related Tutorials/Questions & Answers:
core Java Collections - Java Beginners
core Java Collections   what is Vector? send me any example what is differece between Array and Vector? Why Vector is called Sychronized?  Hi Friend, The Vector implements a growable array of objects
java collections
java collections  what are all the methods and things added for collections in java5 and java6 please kindly reply me as soon as possible
Collections in Java
Collections in Java  What is Concurrent Hash map
Collections in Java
Collections in Java  What is Concurrent Hash map
java collections
java collections  Dear Friends plz help me to complete this program import java.util.*; public class StringDemo { static String a="{a=100;b=200;c=300... achieve this plz without using stringtokenizer with any collections!!!  
collections in java
collections in java  please explain me the flow of this program..i m getting o/p as 2 1 1..y not 2 1 it that if we change the i2 value,it doesnt remove. import java.util.*; public class Mapit { public static void main
collections - Java Interview Questions
collections  The Java Collections API  Hi friend, Java Collections of API (Application Programming Intreface) Consists of several... information on Java Collection API visit to :
java Collections - Java Beginners
java Collections   HI Friends, I want to pick a random element from a set.How can i achieve this.I have a set of objects , I want to pick a random object every time from the set..  Hi Friend, Try
wt are the collections in java
wt are the collections in java  plese send me the reply   Hi Friend, Java Collections API (Application Programming Interface) Consists... tool to the creation of custom data structures. For more information on Java
collections - Java Interview Questions
collections   what is the way to insert map values into a set in collections
/java/jdk6/introduction-collections-api.shtml  Hi, Please send a study material on collections
java collections - Java Beginners
java collections  i need a sample quiz program by using collections and its property reply soon as possible ....   Hi Friend, Try the following code: import*; import java.util.*; class Test { String
Collections - Java Beginners
Collections  I want to know about the new for loop used in collections... can anyone explain in short..? If possible can you give some sites...,
collections - Java Interview Questions
in Array of type Integer. Collections : ArrayList al = new ArrayList
collections in java - Java Interview Questions
collections in java  What is collection
java collections - Java Beginners
java collections  Object o1=new Object("hello"); Object o2=new Object("hello"); is hashmap add these objects?  Hi Friend, The constructor of Object class doesn't contains any parameter. IF you want to any object
Collections in Java
Collections in Java are data-structures primarily defined through a set of classes and interface and used by Java professionals. Some collections in Java that are defined in Java collection framework are: Vectors, ArrayList, HashMap
core java
core java  how to display characters stored in array in core java
core java
core java  what is the Difference between collections and reference... in size collections are not fixed in size. 2) There is no underlying data... is defined. 3) Arrays doesn't prevent duplicate objects while Collections does. 4
collections  why we need collections.when we will use collections in our applications
collections  in collections can we perform binarysearch on arraylist elements without sorting them
core java
core java  basic java interview question
core java
core java  i need core java material   Hello Friend, Please visit the following link: Core Java Thanks
core java
core java  Hi, can any one expain me serialization,Deseralization and exterenalization in core java
core java
core java  Hi, can any one exain me the concept of static and dynamic loading in core java
Core JAva
Core JAva  how to swap 2 variables without temp in java
core java
core java  how can we justify java technology is robust
CORE JAVA  What is Garbage collection in java? What is the role of a developer for garbage collection
core java
core java  its compulsory to save file name and class name is same in java
Core Java
Core Java  How to execute cmd command through java?? Give Code of them
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized


Advertisement null