Java array get random element

Description

Java array get random element


import java.util.Random;
public class Main {
  public static void main(String[] args) {
    String[] peoples = { "CSS", "HTML", "Java", "Javascript", "SQL", "JVM" };
    for (int i = 0; i < peoples.length; i++) {
      int index = new Random().nextInt(peoples.length);
      String anynames = peoples[index];
      System.out.println(anynames);
    }/*from   ww  w .j  a v  a2  s. c  o  m*/
  }
}



PreviousNext

Related