Java获取随机字符串 发表于 2007-03-30 | 分类于 Java 123456789101112import java.util.Random;public static String getRandomString(int length) { StringBuffer buffer = new StringBuffer("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); StringBuffer sb = new StringBuffer(); Random r = new Random(); int range = buffer.length(); for (int i = 0; i < length; i ++) { sb.append(buffer.charAt(r.nextInt(range))); } return sb.toString();} 这个没啥意思,就是随机数用的不多,每次要用都记不住,在这里备个份@@