import java.util.Random; @Test public void randomList() { String[] li = {"中国","美国","英国","法国","德国","俄罗斯"}; Random random = new Random(); for (int j = 0; j < 5; j++) { String country = li[random.nextInt(li.length)]; System.out.println("country = " + country); } }
output =>
country = 法国
country = 中国
country = 俄罗斯
country = 中国
country = 中国