0

I have a lot of code here and I was wondering with this code how I could change it to make my set randomly choose one of the Strings in the set.
My code is here:

import java.util.Set;
import java.util.HashSet;
import java.util.Random;
import java.util.Arrays;
import java.util.ArrayList;

public class Test {
  public static void main(String[] args) {
    Set<String> a = new HashSet<String>();
    Random as = new Random();
    ArrayList<String> suit = new ArrayList<>(Arrays.asList("spades","diamonds","hearts","clubs"));
    a.add( "ace");
    a.add( "2");
    a.add( "3");
    a.add( "4");
    a.add( "5");
    a.add( "6");
    a.add( "7");
    a.add( "8");
    a.add( "9");
    a.add( "10");
    a.add( "Jack");
    a.add( "Queen");
    a.add( "King");
    System.out.println("" + a + " of " + suit.remove(sad.nextInt(suit.size())));
  }
}

I would really like to know as I have not figured it out yet, and it would help a lot in a card game I am making. Any dupes or websites are greatly appreciated.

0 Answers0