package test5;
/**
* 用于添加名字的数组,以任意数组长度添加 初始长度为0,动态增加数组长度
*
* @author
*
*/
public class MyArray {
private String name;
private static int arrlen = 0;
private MyArray a[] = new MyArray[arrlen];
public MyArray() {
super();
}
public MyArray(String name) {
super();
this.name = name;
}
public void setA(MyArray[] a) {
this.a = a;
}
public MyArray[] getA() {
return a;
}
// 添加
public void add(int value) {
int len = this.size() + value;
MyArray[] newArr = new MyArray[len];
for (int i = 0; i < a.length; i++) {
newArr[i] = a[i];
}
this.a = newArr;
}
// 删除
public void remove(int index) {
for (int i = index; i < a.length - 1; i++) {
a[i] = a[i + 1];
}
int newLen = a.length - 1;
MyArray newArr[] = new MyArray[newLen];
for (int i = 0; i < a.length - 1; i++) {
newArr[i] = a[i];
}
this.a = newArr;
}
// 数组长度
public int size() {
return a.length;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return this.name;
}
}