java-获取随机字符串
import java.util.Random; public class getRandomString { public static String excute(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(); } public static void main(String args[]) { String res = excute(4); System.out.println(res); } }
知识只有共享才能传播,才能推崇出新的知识,才能学到更多,这里写的每一篇文字/博客,基本都是从网上查询了一下资料然后记录下来,也有些是原滋原味搬了过来,也有时加了一些自己的想法