J
jrefactors
In the following program that uses Vector. I don't understand
what's the differences among 1,2, and 3, because they produce
the same output. Even I expect (2) and (3) should produce
buffer overflow. any ideas??
import java.util.*;
public class VectorTest
{ public static void main(String[] args)
{
Vector v = new Vector(); //(1): Constructs an empty vector so that its
internal data array has size 10 and its standard capacity increment is
zero.
// Vector v = new Vector(3); //(2): Constructs an empty vector with the
specified initial capacity and with its capacity increment equal to
zero. I expect to have buffer overflow
// Vector v = new Vector(3,2); //(3):Constructs an empty vector with
the specified initial capacity and capacity increment I expect to have
buffer overflow
for (int i=0; i < 20; i++)
{
v.addElement("Jenny_" + i);
}
for (Iterator iter = v.iterator(); iter.hasNext()
{ String data = (String)iter.next();
System.out.println(data);
}
}
}
what's the differences among 1,2, and 3, because they produce
the same output. Even I expect (2) and (3) should produce
buffer overflow. any ideas??
import java.util.*;
public class VectorTest
{ public static void main(String[] args)
{
Vector v = new Vector(); //(1): Constructs an empty vector so that its
internal data array has size 10 and its standard capacity increment is
zero.
// Vector v = new Vector(3); //(2): Constructs an empty vector with the
specified initial capacity and with its capacity increment equal to
zero. I expect to have buffer overflow
// Vector v = new Vector(3,2); //(3):Constructs an empty vector with
the specified initial capacity and capacity increment I expect to have
buffer overflow
for (int i=0; i < 20; i++)
{
v.addElement("Jenny_" + i);
}
for (Iterator iter = v.iterator(); iter.hasNext()
{ String data = (String)iter.next();
System.out.println(data);
}
}
}