Java examples for java.util:Random String
password via random String
//package com.java2s; import java.util.Random; public class Main { public static void main(String[] argv) throws Exception { System.out.println(password()); }/* w ww . j ava 2 s .co m*/ private static String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; public static String password() { Random rnd = new Random(); int len = 8; StringBuilder sb = new StringBuilder(len); for (int i = 0; i < len; i++) { sb.append(AB.charAt(rnd.nextInt(AB.length()))); } return sb.toString(); } }