本文介绍了从字符串数组列表随机字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的数组国家的名单,我想(用随机的可能?),从列表中选择随机的国家,但我还没有发现自己的答案...

这是我到目前为止有:

 的String []列表= {芬兰,俄罗斯,拉脱维亚,立陶宛,波兰};
随机R =新的随机();
 

解决方案

尝试:

 列表[r.nextInt(list.length)];
 

I have list of countries in my array, I would like to pick random country from the list (using random probably?), but I haven't found out the answer myself...

This is what I have so far:

String[] list = {"Finland", "Russia", "Latvia", "Lithuania", "Poland"};
Random r = new Random();
解决方案

Try:

list[r.nextInt(list.length)];

这篇关于从字符串数组列表随机字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 23:42
查看更多