In this post, we will see Vector Data Structure in Java Programming Language | Vector Data Structure Java
Watch this video to know about Vector Data Structure in Java Programming Language:
Watch on YouTube: https://www.youtube.com/watch?v=vz8U-dRFbfw
Program Code: (VectorProg.java)
Watch this video to know about Vector Data Structure in Java Programming Language:
Watch on YouTube: https://www.youtube.com/watch?v=vz8U-dRFbfw
Program Code: (VectorProg.java)
import java.util.Vector; import java.util.Enumeration; public class VectorProg { public static void main(String args[]) { Enumeration e; Vector months = new Vector(3,2); System.out.println("Initial size: " + months.size()); System.out.println("Initial capacity: " + months.capacity()); months.add("Jan"); months.add("Feb"); months.add("March"); months.add("April"); months.add("May"); System.out.println("size: " + months.size()); System.out.println("capacity: " + months.capacity()); months.add("June"); months.add("July"); months.add("Aug"); months.add("Sept"); System.out.println("size: " + months.size()); System.out.println("capacity: " + months.capacity()); months.add("Oct"); months.add("Nov"); months.add("Dec"); System.out.println("size: " + months.size()); System.out.println("capacity: " + months.capacity()); e = months.elements(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); } } } |
Output:
parag@parag-Inspiron-N4010:~/Desktop/prog$ javac VectorProg.java
Note: VectorProg.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. parag@parag-Inspiron-N4010:~/Desktop/prog$ java VectorProg Initial size: 0 Initial capacity: 3 size: 5 capacity: 5 size: 9 capacity: 9 size: 12 capacity: 13 Jan Feb March April May June July Aug Sept Oct Nov Dec |
No comments:
Post a Comment