title: How to shuffle a Hashtable in java
body: <p>I have a constructor in a class, where I initialise a hashtable, consisting of an Integer and a list of Strings. I fill the keys with numbers from 0 to whatever is needed and their corresponding values are Vectors that I create in the constructor beforehand. What I need is to rearrange them randomly (just shuffle them in any way possible), so that when I use getQuest() I will get a random key-value pair that has happened to be on the last spot of the hashtable and delete it at the same time.</p>
  
  <pre><code>public class Quest {
  
  private Hashtable&lt;Integer, List&lt;String&gt;&gt; quests;
  
  public Quest()
  {
      this.quests = new Hashtable&lt;&gt;();
      List&lt;String&gt; mushrooms = new Vector&lt;&gt;();
      mushrooms.add("Choose a mushroom, but be careful not to be poisoned");
      mushrooms.add("mushroom1");
      mushrooms.add("mushroom2");
      mushrooms.add("mushroom3");
      List&lt;String&gt; weapons = new Vector&lt;&gt;();
      weapons.add("Choose a weapon that will help you survive");
      weapons.add("knife");
      weapons.add("rifle");
      weapons.add("sword");
      this.quests.put(0, mushrooms);
      this.quests.put(1, weapons);
  }
  
  public List&lt;String&gt; getQuest()
  {
      return quests.remove(quests.size());
  
  }
  }
  </code></pre>
  
  <p>Also, in case this is not a good idea, is it better to use rand or something like that and get a random pair from somewhere in the hashtable to return (while also deleting it, of course).</p>