Java Vectors Example

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

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&lt;vec.size() k++){ System.out.println(vec.get(k)) } Vector&lt;Integer&gt; vec2 = new Vector&lt;Integer&gt;() //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&lt;vec2.size() k++){ System.out.println(vec2.get(k)) } } }...
View Full Document

Ask a homework question - tutors are online