答案 0 :(得分:0)
如果我理解正确,这就是您想要的
public static String getRandomString(int length) {
char[] chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRST".toCharArray();
StringBuilder sb = new StringBuilder();
Random random = new Random();
for (int i = 0; i < length; i++) {
char c = chars[random.nextInt(chars.length)];
sb.append(c);
}
String randomStr = sb.toString();
return randomStr;
}
您需要像这样的队列来调用此函数。
Queue<String> q = new LinkedList<>();
q.add(getRandomString(10));