Home Answers Viewqa Java-Beginners core Java Collections

 
 


laxman
core Java Collections
1 Answer(s)      3 years and 8 months 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.

Example:

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(primitiveType);
vector.add(wrapperType);
vector.add(str);
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());
vector.removeElementAt(2);
Enumeration e=vector.elements();
System.out.println("The elements of vector: " + vector);
while(e.hasMoreElements()){
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.

Thanks









Related Pages:
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
Collections
/java/jdk6/introduction-collections-api.shtml http://www.roseindia.net/javacodeexamples/index.shtml http://www.devmanuals.com/tutorials/java/collections/index.html...Collections  Hi, Please send a study material on collections
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
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  please explain me the flow of this program..i m getting o/p as 2 1 1..y not 2 1 0..is it that if we change the i2 value,it doesnt remove. import java.util.*; public class Mapit { public static void main
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!!!  
Advance and Core JAVA Topics
Advance and Core JAVA Topics  topics come under core java and topics come under advanced java?   Under Core Java, following topics comes... Interfaces,Packages Threading Exception Handling Applets File Handling Collections
core
core  where an multythread using   Please go through the following link: Java Multithreading
collections - Java Interview Questions
collections   what is the way to insert map values into a set in collections
collections in java - Java Interview Questions
collections in java  What is collection
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 : http://www.roseindia.net
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 Overview
Java NotesCollections Overview Summary of Collections interfaces Most... that the classes implement. Collections - This is a basic set of methods for working... inheritance. The most useful classes are in bold. Collections // Contains may
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..., http://www.roseindia.net/java/jdk6/introduction-collections-api.shtml
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 java.io.*; import java.util.*; class Test { String
collections - Java Interview Questions
in Array of type Integer. Collections : ArrayList al = new ArrayList
Core Java Doubts - Java Beginners
Core Java Doubts  1)How to swap two numbers suppose a=5 b=10; without using third variable? 2)How to sort two strings? By using collections? 3)What... and Encapsulation? 6)Give brief notes over collections? And their usage?  
Core Java Topics
Core Java Topics Following are the topics, which are covered under Core Java. In the roseindia website for core java, programmer will find completed details of every core java topic and simple example of core java that will help you
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
core java
core java  how to display characters stored in array in core java
Java: Collections Class
Java NotesCollections Class The java.util.Collections class contains static utility methods for manipulating collections. Some useful Collections.... There are many more methods in Collections, but the above are a good start. Copyleft
core java
core java  basic java interview question
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  CORE JAVA PPT NEED WITH SOURCE CODE EXPLANATION CAN U ??   Core Java Tutorials
core java
core java  i need core java material   Hello Friend, Please visit the following link: Core Java Thanks
Core Java
Core Java  what is a class
creating own ArrayList without Collections?
creating own ArrayList without Collections?  How can we write our own arraylist without using collections in JAVA
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
collections
collections  in collections can we perform binarysearch on arraylist elements without sorting them
collections
collections  why we need collections.when we will use collections in our applications
core java
core java  surch the word in the given file
CORE JAVA
CORE JAVA  What is called Aggregation and Composition
core java
core java  how can we justify java technology is robust
core java
core java  what is the use of iterator(hase next
core java
core java  please give me following output
core java
core java  write a java program to view product details from product table
Core Java
Core Java  How to execute cmd command through java?? Give Code of them
core java
core java  its compulsory to save file name and class name is same in java
CORE JAVA
CORE JAVA  What is Garbage collection in java? What is the role of a developer for garbage collection
Collections arraylist - Java Interview Questions
Collections arraylist  how we can make array list as syncronised....and what will be the code for that?  Hi Friend, Try the following code: import java.util.*; class SynchronizedArrayList{ public static void
core java
core java  In java primitive variables will get its default value automatically after declaration. Then why it is mandatory to initialize a variable before using
Core Java
Core Java  Please write a Java Program to design login form and store the values in file & validate and display the MainForm
Core Java
Core Java  Hi, Can any one please share the code for Binary search in java without using builtin function
core java
core java  Hello sir,What is logic behinde the core java programms,How may programmas are there,for example,sorting of two numbers,grade of the student details,fibonice serice,paldroma,incremting of the program,asscedding

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.