Package java. Lang .*
The lang Package provides the most basic class package required by Java for development and design. The java. util. * util package provides the event model, Collection framework, datetime tools, and various useful classes.
1, string
A string is a string consisting of a group of characters.
1> statement
String S = "ABC ";
String S = new string ("ABC ");
2> common methods
Trim () removes spaces at both ends of the string;
Replace () replacement;
Indexof (), lastindexof () lookup. If any, an index is returned. If no,-1 is returned;
Startswith (), endswith () to determine whether there is an suffix;
Contains () determines whether it contains;
Tochararray () is converted to a character array;
Getchars (), getbytes () is converted to an array and saved to the specified array;
Format () format the string;
3> Best Practices
Once it is necessary to change the original content, each string method returns a New String object. Therefore, we recommend using stringbuffer and stringbuilder;
String. valueof (), convert other types to string;
2. Math class
ABS () returns the absolute value.
Ceil () returns the smallest integer greater than or equal to the parameter
Floor () returns the maximum integer smaller than or equal to the value of the parameter.
Max () returns the greater limit of the two parameters.
Min () returns a smaller value of the two parameters.
Random () returns a random number of the double type between 0.0 and 1.0, including 0.0 but not 1.0.
Round () returns the rounded integer of the parameter.
Sin (), cos (), Tan () sine, cosine, tangent
SQRT () returns the square root of the Parameter
Pow () returns the second power of the first parameter
3. processing time and date
Java. util. date, which encapsulates a long data, indicates the number of milliseconds that are separated from the time of GMT 00:00:00, January 1, January 1, 1970.
Java. Text. dateformat: format the date
Java. util. calendar, which allows you to flexibly set or read the year, month, day, minute, and second information of a date.
Java. util. gregoriancalendar,
For example:
Date = new date ();
Simpledateformat F = new simpledateformat ("yyyy-Mmmm-dd-eeee ");
System. Out. println (F. Format (date ));
Another example is:
Gregoriancalendar GC = new gregoriancalendar ();
String now = GC. Get (calendar. Year) + "year"
+ GC. Get (calendar. Month + 1) + "month"
+ GC. Get (calendar. Date) + "day"
+ GC. Get (calendar. Hour) + "hour"
+ GC. Get (calendar. Minute) + "Minute"
+ GC. Get (calendar. Second) + "seconds"
4. format the output.
1> Use formatter
Formatter = new formatter (system. Out );
Formatter. format ("% 4 $2 S % 3 $2 S % 2 $2 S % 1 $2 s", "A", "B", "C ", "D ")
//-> "D c B"
% [Argument_index $] [flags] [width] [. Precision] Conversion
Specific settings:
Http://doc.java.sun.com/DocWeb/api/java.util.Formatter
Haowen:
Http://wenku.baidu.com/view/c018ca1efc4ffe473368ab70.html? From = rec & Pos = 0 & Weight = 7 & lastweight = 2 & COUNT = 4