Java Vectors Example

Java Vectors Example - for(int k=0 k<vec.size k...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 import java.util.Vector public class UseVector{ public static void main(String[]args){ Vector<String> vec = new Vector<String>() //create an empty Vector of String vec.add("Java") //add element to rear of vector vec.add("Bob") vec.add("Ann") vec.add(0,"First") //add element at front of vector System.out.println(vec)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for(int k=0 k<vec.size() k++){ System.out.println(vec.get(k)) } Vector<Integer> vec2 = new Vector<Integer>() //create an empty Vector of Integer vec2.add(0) vec2.add(3) vec2.add(0,2) vec2.add(0,4) vec2.add(1) for(int k=0 k<vec2.size() k++){ System.out.println(vec2.get(k)) } } }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online