1.StringBuffer
A.stringbuffer and String:①stringbuffer are a whole new type with no inheritance relationship to String
The appearance of ②stringbuffer is to solve the immutable problem of string content, which is mutable
③stringbuffer never enjoy the special syntax of string (what "+" number concatenation, direct assignment string constant)
New StringBuffer ("Hello");
B. Common methods:
StringBuffer SB2 = Sb.append ("World"); // StringBuffer Stitching at the end of a string = Sb2.insert (5, ""); // StringBuffer Stitching in the corresponding position of the string
Note: Its method is completely not rich in string, most of the methods are related to splicing or deletion, need to pass the location subscript
2.StringBuilder
StringBuilder is an improved version of StringBuffer, the difference is:
①stringbuilder performance is higher than stringbuffer
② However, the StringBuilder thread is unsafe (single threaded), and the StringBuffer thread is safe
3. Packing class
A. Classification: Integer, Character, Byte, short, Long, Float, Double, Boolean
B. Role: ① enriches the problem that the base data type can only hold values, and can also provide a number of methods or constants
The ② wrapper class acts as a bridge between the basic data type and the reference data type
C. Application: Arbitrary conversion of basic data classes, wrapper types, and string types
4. Basic data Type--packing class
A. Basic Transfer packaging:
int a =new Integer (a); // standard procedure in =; //★ Automatic carton Sealing---JDK1.5
B. Basic Packaging:
Integer in =; int b = in.intvalue (); // standard procedure b = in; //★ Automatic Unpacking---JDK1.5 available later
5. Packing class--string
A.string Transfer Package:
String str = "the"new Integer (str);
B. Wrap to String:
Integer in = 325= in.tostring (); // Standard Practice String str1 = in + ""; // in essence, the ToString method of calling in
6.string--Basic
A.string Basic:
String str = "275"; int i = integer.parseint (str); //★ converting string strings to base data types
B. Basic turn String:
int i =n == i + "";
7.Date class--java.util
A. Role: Date class used to encapsulate time and date
long now2 = System.currenttimemillis (); // you can get the number of milliseconds for the current time directly from this method
B. Limitations: Because the date type appears earlier, undergoes changes in the origin of the time, and changes in the JDK version, there are many outdated methods
C. Current usage scenario: ① Gets the current time the program is running or is the most convenient to use date
The ②simpledateformat class can customize the format of the output date time string
③date is available in all versions, making it the first choice to represent time and date
New Date (); // Gets the date object for the current time New Date (0L); // represents time based on the number of milliseconds passed in New SimpleDateFormat ("yyyy mm month DD Day a hh:mm:ss:SSS E"= Sdf.format (now);
D. Disadvantages: ① Sets the value of the object according to the specified date and time----method is obsolete.
② is difficult to remove part of the time date (such as year, month) for a separate time operation.
E. Workaround: Use the calendar as an alternative class to operate
8.Calendar Class--Calendar class
A. Since the calendar is an abstract class, you can get the subclass object directly through. getinstance ().
Calendar cal = Calendar.getinstance (); // use design patterns to help us get directly to the child object of the calendar, which corresponds to the current datetime
The Set/get method of B.calendar
Cal.set (1992,2,14); Cal.set (Cal. Year,1992); Cal.get (Cal. year);
Note: In Java, the month is starting from 0, and the week starts in Sunday, so it takes 1 to operate
C.calendar---> Date
Date birthday = Cal.gettime (); // Method One New Date (Cal.gettimeinmillis ()); // Method Two New SimpleDateFormat ("E"). Format (birthday); // common use of Date and SimpleDateFormat
9.Properties
A. Features: ① Collection Class: Properties is a collection class that stores data in key-value pairs, as well as the ability to manipulate property files (a special format text file)
② action files: Properties both have the ability to manipulate property files (a special format text file)
B. Disclaimer: First produce the Properties collection container
New Properties ();
C. Add: ① Call the SetProperty method into the element, each element is a pair of key-value pairs
② The first parameter is a key and requires no repetition
③ The second parameter is a value
Props.setproperty ("J134001", "Chenguo");p Rops.setproperty ("J134002", "Zhang Peng");p Rops.setproperty (" J134003 "," Zhang Kai ");
D. Modification: If a duplicate value is present, it is equivalent to a modification rather than a new
Props.setproperty ("J134003", "Luo Yi Xiu");
E. Fetch/check: Returns the value from the collection by key, or null if the key does not exist
String name = Props.getproperty ("J134001"); SYSTEM.OUT.PRINTLN (name);
F. Delete: Deletes the entire key-value pair according to the key
Props.remove ("J134002");
G. Length: Gets the number of elements in the container
int size = props.size ();
10.★properties Operation File ★
The A.properties action file must be a fixed-format text file---Properties file---will be the second profile in the work usage ranking
B. Look at the file:. Store method
Props.store (new FileOutputStream ("File/student.properties"), "");
C. read file:. Load method
New Properties (); Newprops.load (new fileinputstream ("file/student.properties"));
Common classes of Java (ii)