Continued
If you can't bear it, you will make a big plan
68.StringBuffer class - upgraded version String - automatic capacity expansion
The bottom layer is new char[16]
If you directly new Stringbuffer
69.StringBuffer class method
Add, delete, modify and query
Add: append();
Delete: delete(2,5)
[ )
Change: setcharAt()
replace(0,5,str)
[ )
Check: charat ()
Insert: insert(5,str)
Length: length
Traversal: toString
Reverse: reverse
70. API of period date
CurrentTimes
SimpleDateForamt
71. Comparator (important)
1.Comparable interface
inherit
rewrite
2.Comparator Comparator com=new Comparator(){ @overwrite Rewrite comparison method }
72. Exhaustive class
enmu Season{
Sping,vacation,FREE
rewrite toString(){ } }
73. Common methods of enmu
values()
value of()
74. Enumeration classes can be set with different methods
Winter{
} When in use: Switch(Season){ case Winter: }
75. Annotation class
1.Retention
Represents the life cycle of a thread
2.Target
Indicates the range that can be modified
76.Collecetion and Map systems
Collection - Collecetion
and
Figure - Map
77. Collection collectionvery important
A way to include data
There are two broad categories:
Collcetion:
List ----------------- ordered and repeatable ----- dynamic array
Set ------------ unordered and non repeated ----- set
-------------Arrarylist(Linear table) List-----------------LinkedList(Linked list) ------------Vector(vector) -------------HashSet Set-----------------LinkdeSet ------------TreeSet
78. Classification of map
Map is the corresponding function
Key Unrepeatable Valu Heavy Key----Value key-----value Group add HashMap Linked HashMap TreeMap Hashtable Properties
79. Methods in the collection interface
add(obj e)
size()
addall(int index, )
costains()
In fact, the "equals method" is used instead of "= ="
Actually rewrites "equals"
costainsAll( collection col);
------Judge whether all sets col exist
remove(Obj obj) --- delete the same content
-------Delete true
-------false not deleted
removeAll(Col col1) -- important!
---------Delete all elements of col1
----------------------------Delete intersection only!!!!
retainAll() ----- find intersection
-----coll has been modified
equals()
hashcode() ------ returns the hash value of the current object
toArray() ----- returns an array
-------What is added and what array is returned
Set - array
{/ / underlying implementation
List list=Arrays.aslist(new String[]{"aa","bb"})
}
80. How do collections traverse?
1.Iterator mode-----------important Code example:
ergodic
first Arraylist array coll coll Add data Then use coll Call iterator a by coll.iterator judge a.hasNext() output a.Next()
Collection coll=new ArrayList(); coll.add(123); coll.add(456); coll.add("Wang jiaoxuan"); coll.add("Fu Mengxue"); coll.add("Ether"); java.util.Iterator a=coll.iterator(); while(a.hasNext()){ System.out.println(a.next()); }
Used for traversal. When calling the iterator, return-----An instance of an iterator Important—————————— In call.Next()The pointer moves down only when call hasNext(),If the pointer does not move, judge whether it exists Next
remove ()
If there is“ Tom" Delete“ Tom" Here, as an example, when and which iteration is compared
Collection coll=new ArrayList(); coll.add(123); coll.add(456); coll.add("Wang jiaoxuan"); coll.add("Fu Mengxue"); coll.add("Ether"); coll.add("Tom"); java.util.Iterator a=coll.iterator(); while(a.hasNext()){ Object obj=a.next(); if("Tom".equals(obj)){ a.remove(); } } java.util.Iterator b=coll.iterator(); while(b.hasNext()){ System.out.println(b.next()); }
2.enhance For-each loop------------No change coll,Just take out the assignment for(obj : coll) { sout(obj) } -------------- from coll in Take it out one by one obj object The output is taken out one by one obj object
81.List --------- dynamic array
1.ArrayList Linear table Automatic capacity expansion-------Default 1.5 times First extension------Plus 10 length JDK7--------The ground floor is hungry Han style JDK8-------The bottom floor is lazy 2.LinkedList Node Is the basic element------Value And pointer (to successor) Value (value of) There are also two-way lists
82. Common methods of list interface
add() add(index,obj)------Insert from index obj indexof()-------First occurrence position lastindexof() remove(index)------Delete the value corresponding to the index remove(value)-----Delete and value Same value set(int index,obj)------Index changed to obj sublist(int start,int end)-------take out---Do not change the original array Add: add Delete: remove change set check get insert add long size ergodic iterator iteration for each strengthen For loop ordinary for loop
83.Set interface
Hashset------------Can save null,Thread unsafe Under each grid Linkedlist Form addition bottom----- Initialize to 16 length Disorder----Hash sorting---So disorder Non repeatability----Every time you add, equals Judgment, no return true add The underlying logic of the method: Hash value region No element---Added successfully There are elements--- Originally n A linked list b a and b Hash values are different----Added successfully a With all current locations equals----identical--fail inequality---success
84. When HashSet calls the add method
Important ------------- override Hashcode() and equals() methods
Use a set of rules This can effectively add judgment!
85.Hashset subclass ----- LinkedHashset
A two-way linked list is added to record the previous and subsequent values
Advantage: frequent traversal – better use
86.Treeset ---- it has its own sorting. Add it and arrange it
Therefore:
Must be of the same type
Must be comparable
You can sort by "natural" and "custom"
87.Map interface -- the play is coming
How do you understand Map? Key---value key---value x=f(x)==y HashMap-----LinkedHashMap HashMap----properties Sorted----TreeMap HashMap--------Thread unsafe and efficient null of key perhaps value -----LinkedHashMap ------When traversing, you can add in order -------For high frequency traversal TreeMap------Add has been sorted, red black tree
88. Understanding of the structure of map interface
Single is entity (key, value) --- one-to-one correspondence
key-----set Save----No repetition value casual characteristic-----No repeat disorder important------key Class in which---rewrite equal()and hashcode()---After all set Well
89. Underlying implementation principle of HashMap
1.instantiation ----The default length is 16 Enty[] 2.with map.put(key1,value1)---take as an example first key1.hashcode()---Judge where to put it--Key Fixed position Judgment position is empty---Added successfully Not empty----If it exists key2 key1.equals(key2)? identical-------Key1 replace key2----Value1 replace value2 Different---plus 3.JDK7---------Enty[]--set Save---Finally Arraylist JDK8--------Node----set Save--Linked list+Red black tree When?----List>14&&surface>8
90.HashMap source code - important!!!!
JDK7-----
Loading factor
critical value
Put method
JDK8-----
Loading factor
Minimum capacity of treelized table
...
91. Underlying source code of LinkedHashMap
Sort in order of addition
92. Method of map interface
Take HashMap as an example
Map map=new HashMap<>(); //add map.put("A",87); map.put("B",87); map.put("C",87); map.put("D",87); //modify map.put("A",120); //remove Object value=map.remove("D"); //clear map.clear(); // map.put("A",87); map.put("B",87); map.put("C",87); map.put("D",87); //get() //sonstainskey //constainsvalue
put ----Add or modify remove------Formal parameter key---Return value value clear----Output null{} query get------key-value containskey containsvalue size isEmpty equals ergodic key value key-value set keyset()-----key use set Stored --Become right set Traversal of value-----Collection Stored --General traversal key-value How to traverse? Entry---use set Stored --set ergodic perhaps First tune key---key One to one correspondence value
93.TreeMap-
1. It is also a key value
2. Keys must be of the same type
3.key must be comparable -- inherit or rewrite com
How to traverse? map.entryset()---entry use set Stored While(hasNext();){ }
94.Collections category (tools)
Same as ArrayLists
reverse()----reversal shaffle---random sort----Sort swap(list,i,j)----exchange max() min() frequencey()----Number of occurrences copy() ----List dest=Array.alist(new object[List.size()]) replaceAll()
This is equivalent to a high-intensity review. It's really a review of the old and know the new!