您的位置:首页 > 其它

经典安全数组实现

2013-01-09 09:28 169 查看
final class DataSources {

private int size;

private DataSource[] data = new DataSource[4];

final int size(){

return size;

}

final DataSource get(int idx){

if (idx >= size)

throw new IndexOutOfBoundsException("Index: "+idx+", Size: "+size);

return data[idx];

}

final void add(DataSource table){

if(size >= data.length ){

DataSource[] dataNew = new DataSource[size << 1];

System.arraycopy(data, 0, dataNew, 0, size);

data = dataNew;

}

data[size++] = table;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐