AbstractList的remove方法 参考一下public void remove() {
if (lastRet == -1)
throw new IllegalStateException();
checkForComodification(); try {
AbstractList.this.remove(lastRet);
if (lastRet < cursor)
cursor--;
lastRet = -1;
expectedModCount = modCount;
} catch(IndexOutOfBoundsException e) {
throw new ConcurrentModificationException();
}
}
解决方案 »
- struts2 web.xml 加上过滤器(为解决中文乱码用)后,请求不到资源。请大家帮忙解决
- Struts+Hibernate+Spring配置连接数据库时报异常,谁给解决发美女图片!
- 中间层用Spring,持久层为hibernate,请问怎么取得数据库表中主键的值增长了多少(比如:mysql的auto_increment值)
- java连数据库
- 求助,关于SimpleFormController
- request的传值问题
- db2数据库链接
- servlet是怎么调试的
- 用过struts+ejb的大侠请帮忙看看
- 100分求教:在resin+iis环境下,在resin.conf中如何设置,才能使iis中多个站点都可以运行jsp文件?
- javamail发送带图片的html信件,图片怎么显示不出来?
- java b/s 客户端为何向服务器传不过字符
class A implements Iteartor{
...
}
数组里删除元素的方法怎么写啊?
用ArrayList来实现,不要用数组不是更好吗?(转贴)
当然。我在这是问一个人家说比较简单的技术问题,并不是说有了ArrayList之流,就不关注细节。我很弱智,
我需要帮助。
private String[] string={"aaa","bbb","ccc","ddd","eee"};
private int count= 4;
public Iterator iterator(){
return new My() ;
} public static void main(String[] agrs){
A a = new A();
Iterator t = a.iterator();
t.remove();
}
class My implements Iterator{
public boolean hasNext(){
if(count<string.length)
return true;
return false;
}
public Object next(){
return string[count++].toString();
}
public void remove(){
String[] temp = new String[string.length-1];
System.arraycopy(string,0,temp,0,count) ;
System.arraycopy(string,count+1,temp,count,temp.length-count) ;
for(int i = 0;i<temp.length;i++){
System.out.println(temp[i]);
}
}
}
}
private String[] string={"aaa","bbb","ccc","ddd","eee"};
private int count= 0;
public Iterator iterator(){
return new My();
} public static void main(String[] agrs){
A a=new A();
for(int i=0;i<a.string.length;i++){
System.out.println(a.string[i]);
}
System.out.println("=============");
Iterator it=a.iterator();
while(it.hasNext()){
System.out.println(it.next()); it.remove();
}
for(int i=0;i<a.string.length;i++){
System.out.println(a.string[i]);
}
}
class My implements Iterator{
public boolean hasNext(){
if(count<string.length)
return true;
return false;
}
public Object next(){
return string[count++].toString();
}
public void remove(){
String[] temp = new String[string.length-1];
System.arraycopy(string,0,temp,0,count-1) ;
System.arraycopy(string,count,temp,count-1,string.length-count) ;
count-=1;
string=temp;
}
}
}