Note that there are some explanatory texts on larger screens.

plurals
  1. POJava LinkedList -- Retrieving the index of an Object
    text
    copied!<p><br> I guess this question that would have already been asked here. I searched but could not find anything similar. So here goes --<br> I have a custom data object <code>Method</code> and <code>Method</code> is as follows --</p> <pre><code>public Class Method { List&lt;String&gt; inputParameters; String resultVariableName; } </code></pre> <p>Now i have a <code>LinkedList&lt;Method&gt;</code> which acts as a repository of <code>Method</code> objects.</p> <p>Given a <code>Method</code> object is there a way in which the correct index of the <code>Method</code> object can be concretely determined.<br> My question arises from the face that <code>LinkedList</code> class has an <code>indexOf</code> routine but this routine returns the first occurrence of the object but then there is no given that 2 copies of <code>Method</code> object can not reside in the <code>LinkedList</code>(right ?)<br> Would tagging every <code>Method</code> object as I add it to the <code>LinkedList</code> solve my purpose and if so is there an ideal way to do it ?</p> <p>EDIT :<br> Explaining my use case a little further.<br> My code basically reads a Velocity template top-down and creates <code>Method</code> objects. One <code>Method</code> object is created for every velocity routine encountered. This explains why the same element can be stored at multiple indices in the <code>LinkedList</code> as there is no real restriction on how many number of time a <code>Velocity</code> routine is called or the inputs/results provided to the <code>Velocity</code> routine.</p> <p>Now, i have a UI component, one <code>JButton</code> per <code>Method</code> object reference in the <code>LinkedList&lt;Method&gt;</code> by using which the user can click and edit the <code>Method</code> object.</p> <p>Thus i need to know which exact <code>Method</code> object reference to edit in the event that same elements reside twice or more number of times in the <code>LinkedList&lt;Method&gt;</code></p>
 

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