Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Can a Vector contain heterogeneous objects in Java?
Since a vector stores elements in the form of objects, you can store objects of various types (heterogeneous) in it.
Example:
import java.util.*;
class Demo{}
public class VectorSample {
public static void main(String args[]) {
Demo obj = new Demo();
Vector v = new Vector(3, 2);
System.out.println("Initial size: " + v.size());
System.out.println("Initial capacity: " + v.capacity());
v.addElement(new Integer(1));
v.addElement(new String("krishna"));
v.addElement(new Float(3.5f));
v.addElement(obj);
System.out.println("Capacity after four additions: " + v.capacity());
}
}
Advertisements