RandomStr

2019-03-19 49 words 1 min read

获取给定长度的全大写字母字符串

private static String getSerialNum(int len) {
	char cha[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };

	StringBuilder sb = new StringBuilder();
	for (int i = 1; i < len + 1; i++) {
		int index = (int) (Math.random() * (cha.length));
		sb.append(cha[index] + "");

		// 四个字母增加一个"-"
		/*if (i % 4 == 0 && i != len) {
			sb.append(cha[index] + "-");
		} else {
			sb.append(cha[index] + "");
		}*/
	}
	return sb.toString();
}

author

Authored By WUHAOTIAN

A gentleman should always strive to improve himself

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it