Shuffle List

-1

I would like to shuffle an ArrayList, and I'm trying to do this with Collections.sort (), but I do not think it's happening

The code I'm using is this:

Thread t = new Thread(new Runnable() {
           @Override
           public void run() {
               ImageView imageView = findViewById(R.id.imagePadrao);
               int m = 0;
               int n = 0;
               List<Integer> op = new ArrayList<Integer>();
               op.add(R.drawable.pedra);
               op.add(R.drawable.papel);
               op.add(R.drawable.tesoura);

               Collections.sort( op );

               Iterator iterator = op.iterator();
               for (int i = 0; i < 6; i++){
                   n++;
                   Log.d("Incremento", ""+n);
                   while (iterator.hasNext()){
                       m = (int) iterator.next();
                       Log.d( "Numero", ""+m );
                       imageView.setImageResource( m );
                       try {
                           Thread.sleep(100);
                       } catch (InterruptedException e) {
                           e.printStackTrace();
                       }
                   }
                   Collections.sort( op );
                   iterator = op.iterator();
               }
           }
       });
       t.start();

To find out if it's shuffling I'm looking at the console and for ever being the same sequence

07-31 12:05:54.591 6136-6168/com.use.jokenpo D/Incremento: 1
07-31 12:05:54.591 6136-6168/com.use.jokenpo D/Numero: 2131099747
07-31 12:05:54.694 6136-6168/com.use.jokenpo D/Numero: 2131099749
07-31 12:05:54.797 6136-6168/com.use.jokenpo D/Numero: 2131099762
07-31 12:05:54.901 6136-6168/com.use.jokenpo D/Incremento: 2
07-31 12:05:54.901 6136-6168/com.use.jokenpo D/Numero: 2131099747
07-31 12:05:55.004 6136-6168/com.use.jokenpo D/Numero: 2131099749
07-31 12:05:55.107 6136-6168/com.use.jokenpo D/Numero: 2131099762
07-31 12:05:55.211 6136-6168/com.use.jokenpo D/Incremento: 3
07-31 12:05:55.211 6136-6168/com.use.jokenpo D/Numero: 2131099747
07-31 12:05:55.317 6136-6168/com.use.jokenpo D/Numero: 2131099749
07-31 12:05:55.419 6136-6168/com.use.jokenpo D/Numero: 2131099762
07-31 12:05:55.522 6136-6168/com.use.jokenpo D/Incremento: 4
07-31 12:05:55.522 6136-6168/com.use.jokenpo D/Numero: 2131099747
07-31 12:05:55.626 6136-6168/com.use.jokenpo D/Numero: 2131099749
07-31 12:05:55.729 6136-6168/com.use.jokenpo D/Numero: 2131099762
07-31 12:05:55.832 6136-6168/com.use.jokenpo D/Incremento: 5
07-31 12:05:55.832 6136-6168/com.use.jokenpo D/Numero: 2131099747
07-31 12:05:55.936 6136-6168/com.use.jokenpo D/Numero: 2131099749
07-31 12:05:56.040 6136-6168/com.use.jokenpo D/Numero: 2131099762
07-31 12:05:56.143 6136-6168/com.use.jokenpo D/Incremento: 6
07-31 12:05:56.143 6136-6168/com.use.jokenpo D/Numero: 2131099747
07-31 12:05:56.250 6136-6168/com.use.jokenpo D/Numero: 2131099749
07-31 12:05:56.353 6136-6168/com.use.jokenpo D/Numero: 2131099762

I would like every time I looped the loop it would scramble again

    
asked by anonymous 31.07.2018 / 14:11

1 answer

1

.sort() serves to sort a list, use .shuffle() to "scramble".

    
31.07.2018 / 21:42