Retrieve LinkedHashSet elements in the insertion order and save them to local variables
<p>I have a linkedhashset from which I need to get elements in the same order they are inserted.
To retrieve, am stuck getting the elements in exact insertion order.</p>

<p>Converting the linkedHashset to List to get by index, but am afraid converting to list would shuffle my elements changing the order</p>

<pre><code>  LinkedHashSet&lt;String&gt; personDetails = new LinkedHashSet&lt;String&gt;();
  //persondetails =&gt; John, kennedy, Female
  List&lt;String&gt; details = new ArrayList&lt;&gt;(personDetails);
  String firstName = details.get(0);
  String lastName = details.get(1);
  String gender = details.get(2);
</code></pre>

<p>Converting to list is throwing off my main objective to retrieve them in insertion order in the first place, as list does not preserve the order.</p>

<p>Can you please suggest me an alternate or my mistake here ?</p>