Java Random create random String example 2
import java.util.Random; public class Main { public static void main(String args[]) { String str1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int length = 10; StringBuilder sb = new StringBuilder(length); Random r = new Random(); for (int j = 0; j < length; j++) { sb.append(str1.charAt(r.nextInt(str1.length()))); }/*from www. j a v a 2s .c o m*/ System.out.println(sb.toString()); } }