您的位置:首页 > 其它

update数组实现

2015-10-20 14:02 302 查看
更新

先看定义:public
void
update(int
i, T dest);

它的意思每个人都知道。使用dest对象替换i位置的对象。

这个操作再简单不过了,一个赋值就OK。

编写代码边分析:

@Override
public
void
update(int
i, T dest) {
//还是先判断异常情况
if(i<0 ||
i>(size-1))
try {
throw
new
Exception(i+" iserror!");
} catch (Exception
e) {
// TODO Auto-generatedcatch block
e.printStackTrace();
}
//安心的更新
container[i] =
dest;
}

测试一下:

@Test
public
void
testUpdate(){
testAdd();
al.update(0,100);
System.out.println(al);
}

这个操作也是没有问题的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: