title: How to shuffle list of images?
body: <p>I'm trying to make a Java desktop application where I want to shuffle image from project folder. I'm able to achieve this but I have to pass the name of pic but I don't want to pass any pic name in my code. I just want to use folder name and it should automatically retrieve all images from there.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class Main1 extends JFrame
  {
        private java.util.List&lt;BufferedImage&gt; list = new ArrayList&lt;BufferedImage&gt;();
      private java.util.List&lt;BufferedImage&gt; shuffled;
      private JLabel label = new JLabel();
         private int width = 708;
      private int height = 800;
      private Timer timer = new Timer(4000, new ActionListener() {
        @Override
         public void actionPerformed(ActionEvent e) {
          update();
         }
     });
  
    public Main1(  )
    {
          super("Simple Timer");
        {
  getContentPane().setBackground(new java.awt.Color(153,153,0));
  } 
   try {
             list.add(resizeImage(ImageIO.read(new File("images\\1.jpg"))));
              list.add(resizeImage(ImageIO.read(new File("images\\2.jpg"))));
              list.add(resizeImage(ImageIO.read(new File("images\\3.jpg"))));
              list.add(resizeImage(ImageIO.read(new File("images\\4.jpg"))));
          } catch (IOException e) {
              e.printStackTrace();
          }
          shuffled = new ArrayList&lt;BufferedImage&gt;(list);
          Collections.shuffle(shuffled);
          timer.start();
           }
  
  private BufferedImage resizeImage(BufferedImage originalImage) throws IOException {
          BufferedImage resizedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
          Graphics2D g = resizedImage.createGraphics();
          g.drawImage(originalImage, 0, 0, width, height, null);
          g.dispose();
          return resizedImage;
      }
  
     private void update() {
        if (shuffled.isEmpty()) {
              shuffled = new ArrayList&lt;BufferedImage&gt;(list);
              Collections.shuffle(shuffled);
          }
  
          BufferedImage icon = shuffled.remove(0);
          jLabel6.setIcon(new ImageIcon(icon));
  }
  </code></pre>