-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaVectorExample.java
More file actions
25 lines (18 loc) · 1001 Bytes
/
JavaVectorExample.java
File metadata and controls
25 lines (18 loc) · 1001 Bytes
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
import java.util.Arrays;
import java.util.Vector;
import java.util.stream.Collectors;
public class JavaVectorExample {
public static void main(String[] args) {
Vector<String> myVector = new Vector<>();
myVector.add("Evren Tan");
myVector.add("Software Crafter");
myVector.addElement("Software Developer");
System.out.println(String.format("My vector capacity is %d", myVector.capacity()));
System.out.println(String.format("The first element of my vector is %s & the last element of my vector is %s", myVector.firstElement(), myVector.lastElement()));
System.out.println(String.format("Is Evren a Software Crafter? %b", myVector.contains("Software Crafter")));
myVector.remove("Software Developer");
System.out.println(String.format("My vector size is %d", myVector.size()));
myVector.add(1, "Co-founder of Turkey Java Community");
System.out.println(Arrays.stream(myVector.toArray()).map(Object::toString).collect(Collectors.joining(", ")));
}
}