Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So it sounds as though you want to keep a history of the prior names for each element in the linked list. I would suggest that you store an array or linked list within each node of the linked list that shows the prior history of that item. For instance:</p> <pre><code>public class Node { Node next; String data; LinkedList&lt;String&gt; history; public Node (String data) { this.data = data; } } </code></pre> <p>You could populate this in many ways, that all really depend upon your use case.</p> <p>Also, why implement your own linked list? Java already comes with a linked list implementation (java.util.LinkedList). I'd suggest using this if you need an ordered list of the linked list variety. If you did this, then create a new data structure to be contained within it that has a name and history, then just maintain the history within that, such as:</p> <pre><code>public class DataItem { String data; LinkedList&lt;String&gt; history = new LinkedList&lt;&gt;(); public DataItem (String data) { this.data = data; } public void setData (String data) { this.history.add(0, this.data); this.data = data; } } </code></pre> <p>Ultimately, remember that strings are immutable in Java. So, a string cannot be modified. You only need to keep a reference to the prior string somewhere, you don't need to copy the value.</p> <p>To ultimately copy a tree of objects, you need to do what's called a deep copy, basically going through the full structure and all collections, and cloning each object into a new object.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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