經過驗證,適合Map<People, List<People>>這種類型,當然people要實現序列化
public Object deepClone(Object source ) { //創建流對象 ByteArrayOutputStream bos = null; ObjectOutputStream oos = null; ByteArrayInputStream bis = null; ObjectInputStream ois = null; //序列化 bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bos); oos.writeObject(source); //當前這個對象以對象流的方式輸出 //反序列化 bis = new ByteArrayInputStream(bos.toByteArray()); ois = new ObjectInputStream(bis); Object copyObj = ois.readObject(); return copyObj;
}