1. String operation
Create string
String s2 = new String("Hello World");
String s1 = "Hello World";
1. String connection
When multiple strings are linked, each string is connected with +, + is the string link, and a new string is generated after the connection.
2. Get the length of the string a.lenght()
Start from 0 according to the index, intercept the length of the string a.substring(1,3); intercept from position 1 to 3 Number position.
3. Get the index position of the specified string indexOf() method; lastIndexOf() method.
indexOf(s) return value: return the index of the first occurrence of s in the string
lastIndexOf(s) return value: return the index of the last occurrence of s in the string
4. Remove the spaces before and after the string trim()
public static void main1 (String[] args){ String a = "abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789" ; for(int i=0;i<4;i++){ int b = (int)(Math.random()*100)%a.length(); String c = a.substring(b, b+1); System.out.print(a.substring(b, b+1)); } } //随机生成不重复的四位数的验证码
public static void main(String[] args){ String a = " <student><xm>张三</xm><xb>男</xb></student>"; String b = a.substring(a.indexOf("<xm>")+4,a.indexOf("</xm>") ); System.out.println("姓名:"+b); String c =a.substring(a.indexOf("<xb>")+4,a.indexOf("</xb>") ); System.out.println("性别:"+c); } //截取姓名和性别
d.get(constant);
d.get(Calendar.YEAR); //Return the digital year
d.get(Calendar.MONTH); //Month
d.get(Calendar.DAY_OF_MONTH); //Day
d.get(Calendar.HOUR); //Hour
d.get(Calendar.MINUTE);//Minutes
d.get(Calendar.SECOND);//Seconds
d.get(Calendar.MILLISECOND);//Milliseconds
yy,yyyy --year
M,MM--month
d, dd --day
h, hh--hour, 12-hour system; HH--hour, 24-hour system
m,mm-minute
s,ss-second
a.set(year, month, day);
a.set(year, month, day, hour, minute, second);
a.set(constant, value);
//c.set(1999,8,12);
//c.set(1999, 2,4,18,55,32);
//c.set(Calendar.YEAR, 1980);
public class Dog { public static void main(String[] args){ Calendar a = Calendar.getInstance(); a.set(2002, 2, 13); SimpleDateFormat b = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss"); String c = b.format(a.getTime()); System.out.println(c); } //格式化日期显示 //时分秒不写是当前时间