0% found this document useful (0 votes)
38 views1 page

Vector App

The document is a Java program that demonstrates the use of the Vector class. It creates a Vector, adds strings as elements, inserts an element at a specific index, prints out the size and capacity of the Vector, iterates through the elements, checks if an element is contained, removes an element, and iterates through the elements again.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views1 page

Vector App

The document is a Java program that demonstrates the use of the Vector class. It creates a Vector, adds strings as elements, inserts an element at a specific index, prints out the size and capacity of the Vector, iterates through the elements, checks if an element is contained, removes an element, and iterates through the elements again.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 1

VectorApp.

java
package vector;

import java.util.*;

public class VectorApp {


public static void main(String[] args) {
Vector v=new Vector();
v.addElement("uno");
v.addElement("dos");
v.addElement("cuatro");
v.addElement("cinco");
v.addElement("seis");
v.addElement("siete");
v.addElement("ocho");
v.addElement("nueve");
v.addElement("diez");
v.addElement("once");
v.addElement("doce");
v.insertElementAt("tres", 2);
System.out.println("nº de elementos "+v.size());
System.out.println("dimensión "+v.capacity());

Enumeration enum=v.elements();
while(enum.hasMoreElements()){
System.out.print(enum.nextElement()+"\t");
}
System.out.println();
if(v.contains("tres")){
System.out.println("Encontrado tres");
}
v.removeElement("tres");
for(int i=0; i<v.size(); i++){
System.out.print(v.elementAt(i)+"\t");
}
System.out.println();

try {
//espera la pulsación de una tecla y luego RETORNO
System.in.read();
}catch (Exception e) { }
}
}

https://translate.googleusercontent.com/translate_c?
depth=1&hl=es&prev=search&rurl=translate.google.com&sl=en&sp=nmt4&u=https://www.
pdfdrive.com/data-structures-and-algorithms-in-java-
e18731618.html&xid=25657,15700002,15700019,15700186,15700191,15700248,15700253&u
sg=ALkJrhj3RlL6kHLHNEzBdhlhqoZqLG7fBA

You might also like