标签:def static 默认 print char system build arraylist aci
版本一内容:public class hel<E>{
private Object[] ele;
private int size; //数组元素个数,类中private int默认为0
private static final int DEFAULT_CAPACITY=10;
public hel() //默认长度
{
ele=new Object[DEFAULT_CAPACITY];
}
public hel(int capacity)
{
ele=new Object[capacity];
}
public void add(E ob) //添加
{
ele[size++]=ob;
}
public String toString() { //重写toString方法,使其打印可视化
StringBuilder sb=new StringBuilder();
sb.append("[");
for(int i=0;i<size;i++)
{
sb.append(ele[i]+",");
}
sb.setCharAt(sb.length()-1, ‘]‘); //将最后一个逗号替换成‘]‘
return sb.toString();
}
public static void main(String[]args)
{
hel s1=new hel();
s1.add("aa");
s1.add("bb");
System.out.println(s1);
}
}
标签:def static 默认 print char system build arraylist aci
原文地址:https://blog.51cto.com/14437184/2419130