代码如下:
- package DataStruct;
- public class Array {
- private int[] data;
- private int[] size;
- public Array(int capacity) {
- data = new int[capacity]
- size = 0
- }
- // 构造函数, 传入数组的容量 capacity 构造 Array
- public Array() {
- this(10);
- }
- // 无参数的构造函数, 默认数组的容量是 capacity=0
- public int getSize() {
- return size;
- }
- // 获取数据中的元素个数
- public int getCapatity() {
- return data.length;
- }
- // 获取数据的容量
- public boolean isEmpty() {
- return size == 0;
- }
- }
来源: http://www.bubuko.com/infodetail-2806616.html