1. String operation
Create a string
String s2 = new String("Hello World");
String s1 = "Hello World";
1. String connection
When multiple strings are linked, each string is connected by +, and + is a string link. After the connection, a new string is generated.
2. Get the string length a.lenght()
According to the index, the string length a.substring(1,3) is intercepted; the number 3 is intercepted from bit 1.
3. Get the index position of the specified string. IndexOf() method; lastIndexOf() method.
indexOf(s) Return value: Return value index of s appears for the first time in the string
lastIndexOf(s) return value: Returns the index of the last occurrence of s in the string
4. Remove the space before and after string trim()
5. Replace all string replace() methods that match the string
6. Determine whether the string is equals() method
When comparing strings with equals(), it is strictly case sensitive. Under this condition, if the two strings still have the same characters and lengths, it returns true, and if it is not the same, it returns false.
7. Determine the starts of a string startsWith() method determines the endsWith() method
The method is used to determine whether the current string object starts or ends with the characters specified by the parameter.
8.Case conversion
Convert uppercase letters in strings to lowercase toLowerCase() method;
Convert lowercase letters in a string to uppercase toUpperCase() method.
9. String split (String sign) method
This method completely splits the string according to the established separator.
Operation:
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)); } }// Randomly generates unrepeated four-digit verification code public static void main(String[] args){ String a = " <student><xm>Zhang San</xm><xb>Male</xb></student>"; String b = a.substring(a.indexOf("<xm>")+4,a.indexOf("</xm>") ); System.out.println("name:"+b); String c =a.substring(a.indexOf("<xb>")+4,a.indexOf("</xb>") ); System.out.println("Gender:"+c); } //Intercept the name and gender2. Date operation: Calendar
(I) Reading date
Calendar a = Calendar.getInstance();
d.get(constant);
d.get(Calendar.YEAR);//Return to the number year
d.get(Calendar.MONTH);//month
d.get(Calendar.DAY_OF_MONTH);//Day
d.get(Calendar.HOUR);//
d.get(Calendar.MINUTE);//minute
d.get(Calendar.SECOND);//Second
d.get(Calendar.MILLISECOND);//milliseconds
Format display of date:
Format the monitor using date SimpleDateFormat
1. Calendar of date
Calendar a = Calendar.getInstance();
2. Make a formatter
SimpleDateFormat f = new SimpleDateFormat("Format Style");
yy,yyyy --Year
M,MM--Moon
d,dd --day
h,hh--, 12-hour system; HH--, 24-hour system
m,mm-point
s,ss-second
3. Format calendar
f.format(date); //Note that it is Date, not Calendar;
f.format(a.getTime()); //Use the getTime() function of the Calendar object to convert it into a Date object
(II) Write date
Calendar a = Calendar.getInstance();
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("yyyyy year MM month dd date HH:mm:ss"); String c = b.format(a.getTime()); System.out.println(c); }//Format date display//Time, minute and second not to write is the current timeThe above is all the content of this article. I hope that the content of this article will be of some help to everyone’s study or work. I also hope to support Wulin.com more!