验证码
String a=new String("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
String yzm="";
for(int i=0;i<4;i++){
int sj=(int)(Math.random()*1000);
int b =sj%a.length();
yzm +=a.substring(b, b+1);
}
System.out.println(yzm);
截取字符串
String a=new String("<student><name>张三</name><sex>男</sex><class>1116班</class></student>");
String a1=a.replaceAll("<student>", "").replaceAll("</student>", "");
int name=a1.lastIndexOf("<name>");
int name1=a1.indexOf("</name>");
int sex=a1.lastIndexOf("<sex>");
int sex1=a1.indexOf("</sex>");
int i =a1.lastIndexOf("<class>");
int j =a1.indexOf("</class>");
String xingming=a1.substring(name+6, name1);
String xingbie=a1.substring(sex+5,sex1);
String banji=a1.substring(i+7,j);
System.out.println("姓名:"+xingming+"
"+"性别:"+xingbie+"
"+"班级:"+banji);
时间的读写操作
Calendar a=Calendar.getInstance();
int year =2016;
int month=8;
int date=12;
a.set(year, month,date); //赋值
SimpleDateFormat b=new SimpleDateFormat("yyyy-MM-dd"); //定义一个格式化工具
String c=b.format(a.getTime()); //格式化
System.out.println(c);