有代码么?
用clone();
两个内容同时变化

解决方案 »

  1.   

    LinkedList l1=new LinkedList();
    l1.add("1231312");
    l1.add("fdffd");LinkedList l2=(LinkedList) l1.clone();
    System.out.println(l1==l2); 
    l1.add("fffff");System.out.println(l1);
    System.out.println(l2);
      

  2.   

    Do you mean the following case?/***************************/
    l1.add(map)
    l2=(LinkedList) l1.clone();
    ...
    //map's content changed here
    //both l1 and l2 are changed
    /****************************/If so, you have to iterate the contents of l1, and add the clone of each element into l2.
      

  3.   

    Yes,How to do it?please tell me the code.thanks
      

  4.   

    Iterator i=l1.iterator();
    while(i.hasNext()){
        l2.add(((Map) i.next()).clone());
    }
      

  5.   

    解决办法就是必须要在内存中产生新的对象拷贝。
    在JAVA中,能够在内存中产生新的对象有三种方式:
    (1) new
    (2) clone
    (3) 反序列化楼主你自己看看应该怎么做呢?
      

  6.   

    大致可以这么解释:
    <<
    序列化:
    对象 ---> 字节流反序列化:
    字节流 ---> 对象
    >>
      

  7.   

    不好意思。
    意思理解了
    用JAVA怎样表示呢?
      

  8.   

    clone(),对于你自己写的类要覆盖Object的clone()方法,也就是集合里的每个元素(对象)都要实现clone()方法(递归的,也就是该对象的属性也必须是可以clone()的,即所谓的深clone)
      

  9.   

    如果你LinkedList里装的对象的属性是原类型的,则直接可以clone.
      

  10.   

    请参照下例(如果运行需要junit),实现了一个序列化和反序列化的过程:
    <<
    public class TestSerialization extends TestCase {
        public TestSerialization(String name) {
            super(name);
        }    public void testSerialization() throws Exception {
            Data d1 = new Data();
            d1.forTest = 99;        ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(d1);
            oos.close();        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bis);
            Data d2 = (Data) ois.readObject();
            ois.close();        assertNotNull(d2);
            assertNotSame(d1, d2);
            assertEquals(d1.forTest, d2.forTest);
        }
    }class Data implements Serializable {
        int forTest;
    }
    >>
      

  11.   

    哦。
    这样实现对吧?
    LinkedList list = new LinkedList();
    HashMap map = new HashMap();
    map.put("a","1");
    list.add(map);LindedList cloneList = new LinkedList();
    HashMap map1=new HashMap();
    map1=(HashMap)map.clone();
    cloneList.add(map1);
      

  12.   

    我开玩笑呢,"xiaohaiz"别生气:)
      

  13.   

    ^O^请问大哥有email么?
    以后有问题直接找你行么?
    小女子这相礼过去了:)
      

  14.   

    编程的女孩子啊...
    [email protected]