欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java生成随机的字母数字字符串,java生成字符串,java生成随机的字母数

来源: javaer 分享于  点击 5815 次 点评:72

java生成随机的字母数字字符串,java生成字符串,java生成随机的字母数


java生成随机的字母数字字符串:

import java.util.Random;public class RandomString{  private static final char[] symbols = new char[36];  static {    for (int idx = 0; idx < 10; ++idx)      symbols[idx] = (char) ('0' + idx);    for (int idx = 10; idx < 36; ++idx)      symbols[idx] = (char) ('a' + idx - 10);  }  private final Random random = new Random();  private final char[] buf;  public RandomString(int length)  {    if (length < 1)      throw new IllegalArgumentException("length < 1: " + length);    buf = new char[length];  }  public String nextString()  {    for (int idx = 0; idx < buf.length; ++idx)       buf[idx] = symbols[random.nextInt(symbols.length)];    return new String(buf);  }}
相关栏目:

用户点评