- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What does the method int capacity() do in java?
The capacity() method is used to return the current capacity of a vector. Capacity is the length of the array kept in the vector.
Example
import java.util.Vector; public class VectorDemo { public static void main(String[] args) { Vector<Integer> vec = new Vector<Integer>(); vec.add(14); vec.add(13); vec.add(12); vec.add(11); vec.add(4); vec.add(3); vec.add(2); vec.add(1); System.out.println("Capacity of the vector is :"+vec.capacity()); } }
Output
Capacity of the vector is :10
Advertisements