解决方案 »

  1.   

    index = messages.indexOf(????);这边实现不了这样的功能
    笨点可以这样写
    /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub MessageBoardBean bean1 = new MessageBoardBean("红楼梦","红楼梦的相关故事","曹雪芹");
    MessageBoardBean bean2 = new MessageBoardBean("红楼梦1","红楼梦的相关故事1","曹雪芹1");
    MessageBoardBean bean3 = new MessageBoardBean("红楼梦2","红楼梦的相关故事2","曹雪芹2");
    List<MessageBoardBean> list= new ArrayList<MessageBoardBean>();
    list.add(bean1);
    list.add(bean2);
    list.add(bean3);

    List<MessageBoardBean> newlist=removeObj(list,"红楼梦1","红楼梦的相关故事1","曹雪芹1");
    }

    public static List removeObj(List<MessageBoardBean> list,String title,String author,String content){
    for(int i=0;i<list.size();i++){
    MessageBoardBean bean = list.get(i);
    if(bean.getTitle().equals(title)&&bean.getAuthor().equals(author)&&bean.getContent().equals(content)){
    list.remove(i);
    }
    }
    return list;
    }
      

  2.   

    你remove里边直接放MessageBoardBean 对象不是可以删除的吗
      

  3.   

    不行的那样会显示MessageBoardBean cannot be resolved to a variable
      

  4.   

    Quote: 引用 1 楼 shixitong 的回复:

    那为什么 indexOf 方法不能实现呢
      

  5.   

    remove后面不是索引吗,直接把索引放进去不完了,索引设成变量的形式,整形的
      

  6.   

     int java.util.List.indexOf(Object o)
    Returns the index of the first occurrence of the specified element in this list,
     or -1 if this list does not contain the element. More formally, 
     returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), 
     or -1 if there is no such index.
     
     是这样的
     indeOf是查找o这个对象在list中存不存o.equals(get(i)),用的是equals
     
     除非你重写equals方法,否则你新构建的对象肯定和list中的对象不相等(即你不可能得到你要删除对象在list中索引)
      

  7.   

    1、remove后面即可以是索引也可以是对象
    2、他目前这种情况只知道3个变量的值,并不知道索引
      

  8.   

    用迭代器从list里面先拿到对象,判断下是不会死你要删除的,是的就直接remove呗