StringBuffer与StringBuild建议使用后者
str1.deletcharat()//删除指定位置上的字符
str1.reverse()//字符反转
随机数:随机的生成的任意的一个数,理论上讲具有不可预知性
Random 伪随机数
通过相同的种子 产生的随机数是相同的
//生成伪随机数
Random r1=new Random(10);
System.out.println(r1.nextInt());
System.out.println(r1.nextInt(100));//一百以内
System.out.println(r1.nextBoolean());
System.out.println(r1.nextInt());
TreadLocalRandom
本地线程 减少多线程资源竞争,保证线程安全
继承与Random
因为构造器 是默认访问 故提供了Crrent返回当前对象
ThreadLocalRandom random=ThreadLocalRandom.current();
random.nextInt(34,179)//34到179之间的随机数
UUID
String uuid=UUID.randomUUID().toString();//一般用来表示一个随机的唯一字符串,
验证码制作:
String str=”ABCDJELASNDASLDMAS”;
str+=str.toLowerCase();
str+=”0123456789”;
StringBuild sb=new StringBuild(5);
char ch=str.charAt(new Random().nextInt(str.length()));
for(int i=0;i<5;i++)
{
char ch=str.charAt(new Random().nextInt(str.length()));
}