Hello, I need to create a queue using vectors in Java and I do not understand why the condition does not work when my vector is full.
import java.util.Vector;
public class ColaVector {
private Vector<Integer> cola = new Vector<Integer> (3);
public int elementosEncolados = 0;
public void insertarAlFinal(int elemento) {
if (this.elementosEncolados <= this.cola.size()) {
this.cola.add(elemento);
this.elementosEncolados++;
} else {
System.out.println("No se puede insertar. Cola llena");
}
public int primerValor() {
return cola.firstElement();
}
}
Here is the main class from which I call all the classes shown in the previous table and as you can see my vector of 4 elements is full and when printing on the screen the first value should also show that it is full.
public class Main {
public static void main(String[] args) {
ColaVector c1 = new ColaVector();
c1.insertarAlFinal(1);
c1.insertarAlFinal(2);
c1.insertarAlFinal(3);
c1.insertarAlFinal(4);
c1.insertarAlFinal(5);
c1.insertarAlFinal(6);
c1.insertarAlFinal(7);
System.out.println( c1.primerValor() );
}
}