forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector_Demo.java
More file actions
52 lines (48 loc) · 1.64 KB
/
Vector_Demo.java
File metadata and controls
52 lines (48 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package utilpck;
import java.util.Vector;
public class Vector_Demo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Vector<Object> v = new Vector<>(); // vector<> here <> means generic datatype it means run time it will decide
// which datatype
// data is passed. if we want to pass any specific data type then it is allow.
/*
* Vector v1 = new Vector(); v1.add(14);
*/
System.out.println("1)capacity : " + v.capacity());
v.ensureCapacity(30);
System.out.println("After ensuring capacity is : " + v.capacity());
v.add(12);
v.add(10.5f);
v.add('b');
v.add("balajiinfotech");
System.out.println("Vector : " + v);
/*
* alternate option Integer i = new Integer(10); v.addElement(i);
* System.out.println(v);
*/
System.out.println("2)indexOf : " + v.indexOf('d'));
System.out.println("3)contains : " + v.contains(12));
System.out.println("4)size : " + v.size());
System.out.println("5)toString : " + v.toString());
// System.out.println("6) : "+v.copyInto()); If interger array are there and we
// want to copy vector element in that array then this
// method is used.
/*
* v1.addAll(v); for (Object s : v) { System.out.println(s); }
*/
System.out.println("6)elementAt : " + v.elementAt(2));
System.out.println("7)firstElement : " + v.firstElement());
System.out.println("8)get : " + v.get(3));
System.out.print("9)insertElementAt : ");
v.insertElementAt("zeronsec", 3);
System.out.println(v);
System.out.print("10)set : ");
v.set(4, "balajiinfosec");
System.out.println(v);
// clear , remove , clone , trimToSize , containsall
}
}