publicclassExpandableArrayDriver{publicstaticvoidmain(String[]args){ExpandableArrayea=newExpandableArray(1);System.out.println("size:"+ea.size());for(inti=0;i<10;i++){ea....
public class ExpandableArrayDriver
{
public static void main(String[] args)
{
ExpandableArray ea = new ExpandableArray(1);
System.out.println("size: " + ea.size());
for (int i = 0; i < 10; i++)
{
ea.add(new Integer(i));
}
System.out.println("size: " + ea.size());
for (int i = 0; i < ea.size(); i++)
{
System.out.print(ea.get(i) + " ");
}
System.out.println();
}
}
public class ExpandableArray
{
private Object[] data;
private int size = 0;
public ExpandableArray(int cap)
{
data = new Object[cap];
}
public int size()
{
return size;
}
public Object get(int i) throws ArrayIndexOutOfBoundsException
{
if (i < 0 || i >= size)
{
throw new ArrayIndexOutOfBoundsException(i);
}
return data[i];
}
----------------------------------continue--------------------------------
展开