import java.util.List;
import java.util.Vector;
/**
* {@link <a href=
* "https://[Log in to view URL]"
* target= "_blank">Primitive Vector<E></a>}
*
* @author itammb ( Italia Massimiliano Buscati )
* @version JDK 1.15
*
*/
class Main {
/**
* @see Vector#ensureCapacity(int)
* @see Vector#capacity()
*
*/
public static void applayMethodEnsureCapacity(Vector<Integer> buffer, int minCapacity) {
buffer.ensureCapacity(minCapacity);
applayLoop(buffer);
System.out.println(buffer.capacity());
buffer.add(4);
buffer.add(5);
System.out.println(buffer.capacity());
applayLoop(buffer);
}
/**
* @see Vector#copyInto(Object[])
*
*/
public static void applayMethodCopyInto(Vector<Integer> buffer) {
applayLoop(buffer);
Object[] copy = new Object[buffer.size()];
buffer.copyInto(copy);
// verifica l'indipendenza della struttura
println(copy);
copy[0] = -1;
println(copy);
applayLoop(buffer);
}
/**
* @see List#size()
* @see List#get(int)
*
*/
public static void applayLoop(Vector<Integer> buffer) {
if (buffer.isEmpty())
System.out.print("[]");
else
for (int i = 0; i < buffer.size(); i++)
System.out.print("[i=" + i + ", e=" + buffer.get(i) + "] ");
println();
}
private static void println() {
System.out.println();
}
private static void println(Object[] objArray) {
for (int i = 0; i < objArray.length; i++)
System.out.print("[i=" + i + ", e=" + objArray[i] + "] ");
println();
}
/**
* @see Vector#add(Object)
*
*/
private static Vector<Integer> createBufferTest() {
return new Vector<Integer>(4) {
private static final long serialVersionUID = -69L;
{
add(1);
add(2);
add(3);
}
};
}
public static void main(String args[]) throws Exception {
// Unit test - capacità di memorizzazione predefinita
applayMethodEnsureCapacity(createBufferTest(), 4);
// Unit test - copia di una struttura
applayMethodCopyInto(createBufferTest());
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: