20200810-Java high-level API summary

1. Collection framework

List: ordered
ArrayList: variable-length array, easy to find and random access
LinkedList (Node): doubly linked list, easy to insert and delete (for Node's next and pre)
Set: not repeated
HashSet: HashMap key hashCode () Together with the equals() method to ensure that there is no repeat
addAll() to convert between Set and List
Map:Entry<k,v> key-value pair Entry is a static class of Map
Traversal: List: fori, enhanced for, iterator while hasnext
Set: Enhanced for, iterator
Map: entrySet() KeySet() values()
Generic: Define the input and output of the set type Comparable
add()/put()/addAll()
remove()
set()/put( )
ger() HashSet has no get method, because there is no subscript/List is a get subscript, Map is a traversal key
Collections: ComparAble
new Comparator{int compare(Student o1,Student o2){return o1.stuId-o2.stuId} } Compare two of the same type, in ascending order

2. Practical

Packing type: convenient for generic use and conversion to String type.
Packing: change the basic data type to the packing type.
Unboxing: convert the packing type to the basic data type
Integer a=1;//Auto-boxing
int b=new Integer (12);//Automatic unboxing, generally used in the return value of the method, when the parameter list is passed
Math class: mathematical formula
Random class: various random numbers, seeds, once the seeds are added, it is pseudo-random
enumeration class: special The class, private structure, and the directly written values ​​are all objects of the current type
String: the bottom layer is a character array constant, unchangeable
indexof, split, charAt, substring intercepted string directly pass a parameter, where to intercept from the beginning, two Parameter, from the subscript of the first parameter to the subscript of the second parameter, left closed and right opened
toCharArray converted to char array, suitable for the case of Chinese getBytes converted to byte array
StringBuffer: thread safe, slower
append (),toString()
StringBuilder is a single-threaded, fast, variable-length character array. The bottom layer is a variable. Initially 16, it can be expanded.
Date: System.currentTimeMillis() The UTC time displayed by default.
SimpleDateFormat time format: "yyyy- MM-dd HH:mm:ss.S "Generally, milliseconds (.S) are not used

3, io style:

InputStream OutputStream Reader Writer
Ordinary Stream: FileInputStream FileOutputStream FileReader FileWriter
Conversion Stream: InputStreamReader OutputStreamWriter, Conversion Stream and Character Encoding
Advanced Stream:
Buffer Stream:
Read line by line, write the entire string, only install Reader and Writer, put the stream first when it is idle One-step reading into the buffer
BufferedReader, BufferedWriter
binary stream:
first put the picture, video, audio, etc. to be transmitted into the file stream, and
then load the file stream into the DataInputStream, DataOutputStream is
relatively safe
Object stream: the
object must first implement the Serializable interface, ObjectInputStream And ObjectOutputStream
reading process:
1. Put the file into the file input stream, first define the way to handle the exception
2. read() read(b) …read range Byte array (put into the string)
3. Close the stream
writing Process:
basically similar to the reading process, load the output path into the stream and write the string into it

4. Multithreading

Inherit the Thread class and implement
the difference between the Runnable interface start() and run(): start is the method to realize multithreading, run is the normal method start calls start(0) and then run(method) to
implement the Callable interface: call() method There is no big difference between return value (generic) and run() method
FutureTask task=new FutureTask (object of the implementation class of Callable interface);
Thread t=new Thread(task);
t.start();
task.get( );//You can get its return value

5. Reflection: Obtain objects, manipulate objects and their attributes and methods at runtime

Type.class, object.getClass(), Class.forName("the full path of the class");
get the constructor (getDeclaredConstructor()) newInstance()
method (getDeclaredMethod("method name", parameter type)) invoke (corresponding Parameter)
attribute (getDeclaredField("attribute name")) set() is
not enough permissions need to execute setAccessible(true);

6, xml sum json

xml format: <?xml version="1.0" charset="UTF-8"?>
Root tag, one-to-one correspondence (with beginning and ending)
Function: data transmission (basically abandoned), configuration file
DOM acquisition:
1 、DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
2.DocumentBuilder builder = factory.newDocumentBuilder(); 3.Document
document=builder.parse("xml path/or get it in the form of InputStream");
4.Element e=document. getElementById/document.getElementsByName("tag name");
5. e.item(0);
Dom save:
1. TransformFactory tf=TransformFactory.newInstance();
2. Transform t=f.newTransform();
3. DomSource s =new DomSource(document);
4. StreamResult sr=new StreamResult (the writer object is loaded into the target address);
5. tf.transform(s,sr);
json: The object must implement the Serializable interface
object to json format string: JSON. toJSONString(object);
Object to json JSON.toJSON/JSON.parseObject(json string);
json to object JSON.toJavaObject(json object, java object type.class);

7. Regular expression: regular expression

Matching rules

Guess you like

Origin blog.csdn.net/qq_42005540/article/details/107919600