Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From your question I guess that you need <strong><em>deep copy</em></strong> of the object . If this is the case don't use <a href="http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#clone%28%29" rel="nofollow"><code>clone</code></a> method as it is already specified in <code>oracle docs</code> that it provides <strong><em>shallow copy</em></strong> of the associated object. And I don't have enough idea about <code>BeanUtils.copyProperties</code> API.<br>Given below is the short demo of <code>deep copy</code>. Here I am deep copying a <code>primitive array</code>. You can try this code with any type of object.</p> <pre><code>import java.io.*; class ArrayDeepCopy { ByteArrayOutputStream baos; ByteArrayInputStream bins; public void saveState(Object obj)throws Exception //saving the stream of bytes of object to `ObjectOutputStream`. { baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(obj); oos.close(); } public int[][] readState()throws Exception //reading the state back to object using `ObjectInputStream` { bins = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream oins = new ObjectInputStream(bins); Object obj = oins.readObject(); oins.close(); return (int[][])obj; } public static void main(String[] args) throws Exception { int arr[][]= { {1,2,3}, {4,5,7} }; ArrayDeepCopy ars = new ArrayDeepCopy(); System.out.println("Saving state..."); ars.saveState(arr); System.out.println("State saved.."); System.out.println("Retrieving state.."); int j[][] = ars.readState(); System.out.println("State retrieved..And the retrieved array is:"); for (int i =0 ; i &lt; j.length ; i++ ) { for (int k = 0 ; k &lt; j[i].length ; k++) { System.out.print(j[i][k]+"\t"); } System.out.print("\n"); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload