title: How can I shuffle an array and put them into buffered images?
body: <p>Basically I'm making a domino game in Java; however I'm pretty new and can't figure out how to shuffle the dominoes up using arrays and buffered Images.</p>
  <p>This code here is setting up the arrays for each hand and an array with each domino piece. Keep in mind that I am not using an AI for this domino game;
  the program runner will just play as each player.</p>
  <pre><code>static String [] hand1 = new String[7];
  static String [] hand2 = new String[7];
  static String [] hand3 = new String[7];
  static String [] hand4 = new String[7];
  static String[] allDominoes = {&quot;00&quot;,&quot;01&quot;,&quot;02&quot;,&quot;03&quot;,&quot;04&quot;,&quot;05&quot;,&quot;06&quot;,&quot;11&quot;,&quot;12&quot;,&quot;13&quot;,&quot;14&quot;,&quot;15&quot;,&quot;16&quot;,&quot;22&quot;,&quot;23&quot;,
            &quot;24&quot;,&quot;25&quot;,&quot;26&quot;,&quot;33&quot;,&quot;34&quot;,&quot;35&quot;,&quot;36&quot;,&quot;44&quot;,&quot;45&quot;,&quot;46&quot;,&quot;55&quot;,&quot;56&quot;,&quot;66&quot;};
  </code></pre>
  <p>This is what I tried to use to shuffle the dominoes and put them into each hand array:</p>
  <pre><code>public static void newRound() // start a new round; shuffle the dominoes; hand them out
  {
      
  Arrays.fill(hand1, null);
  Arrays.fill(hand2, null);
  Arrays.fill(hand3, null);
  Arrays.fill(hand4, null);
  
  String[] shuffledDominos = new String[28];
  List&lt;String&gt; shuffled = Arrays.asList(allDominoes);
  
  Collections.shuffle(shuffled);
  
  shuffled.toArray(shuffledDominos);  
  
      int pos = 0;
      
      for (int j = 0; j &lt; 7; j++)
      {
          hand1[pos] = shuffledDominos[j];
          pos++;
      }
      pos = 0;
      for (int y = 7; y &lt; 14; y++)
      {
          hand2[pos] = shuffledDominos[y];
          pos++;
      }
      pos = 0;
      for (int x = 14; x &lt; 21; x++)
      {
          hand3[pos] = shuffledDominos[x];
          pos++;
      }
      pos = 0;
      for (int z = 21; z &lt; 28; z++)
      {
          hand4[pos] = shuffledDominos[z];
          pos++;
      }
  </code></pre>
  <p>However I think this part is completely wrong and there must be a better way of doing this since I'm not sure how to actually proceed from here on out.</p>
  <p>This is assigning each domino Image the domino pngs.</p>
  <pre><code>public DominoPanel() 
  {
      
      try
      {
          dom00 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/00.png&quot;));
          dom01 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/01.png&quot;));
          dom02 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/02.png&quot;));
          dom03 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/03.png&quot;));
          dom04 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/04.png&quot;));
          dom05 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/05.png&quot;));
          dom06 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/06.png&quot;));
          dom11 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/11.png&quot;));
          dom12 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/12.png&quot;));
          dom13 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/13.png&quot;));
          dom14 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/14.png&quot;));
          dom15 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/15.png&quot;));
          dom16 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/16.png&quot;));
          dom22 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/22.png&quot;));
          dom23 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/23.png&quot;));
          dom24 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/24.png&quot;));
          dom25 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/25.png&quot;));
          dom26 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/26.png&quot;));
          dom33 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/33.png&quot;));
          dom34 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/34.png&quot;));
          dom35 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/35.png&quot;));
          dom36 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/36.png&quot;));
          dom44 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/44.png&quot;));
          dom45 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/45.png&quot;));
          dom46 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/46.png&quot;));
          dom55 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/55.png&quot;));
          dom56 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/56.png&quot;));
          dom66 = ImageIO.read(DominoPanel.class.getResource(&quot;/Image/66.png&quot;));
          
      }
      catch(Exception E)
      {
          
      }
  </code></pre>
  <p>I know I probably didn't explain this well so I will try to summarize it here as best as I can. I need to be able to assign a random domino to each player and then print them out in a JPanel using buffered Images.</p>