Java Learning Note (2015.7.27~7.31) Java Learning Note (2015.7.27~7.31)
Java课堂
Day16
Review
1. Plastic Surgery
The basic unit of data is bit (bit).
| type |
bit |
Kb |
Range |
| Byte |
8 Guests |
1 bytes |
-128~127 (2^8) |
| Short |
16 Guests |
2 bytes |
-32768~32767 (2^16) |
| Int |
32 Guests |
4 bytes |
Very big, slightly |
| Long |
64 guests |
8 bytes |
Ash is often large, slightly |
2, the conversion of the value
Char is converted to int by using ASCII (English pronunciation/ski/).
3, the procedure of the Organization
Order
Branch
Cycle
4. FAQ for method rewriting
-
Duplicate Method Study () in Type Student class
Method repeats.
-
The constructor Student () is undefined
Construction method Not defined
-
Constructor call must is the first statement in a Constructor
The This () call overload (overload) Construction method must be in the first row
-
The static field Chinese.guoji should be
Accessed in a static
Static Call static
Day181, Container Collection1, Concept: An object that holds multiple objects. 2. Why does the JDK provide the container
Features that almost all programmers need
3. API
Application Interface Application Programming Interface
4, the function of the container
5. Common methods of collection interface
-
int size ();
-
Boolean isEmpty ();
-
void Clear ();
-
Boolean contains (Object element);
-
Boolean Add (Object element);
-
Boolean remove (Object element);
6. Operation between containers (learn)
-
Boolean cotainsall (Collection c);
-
Boolean addadd (Collection c);
-
Boolean RemoveAll (Collection c);
-
Boolean retainall (Collection c);
7, List of features
8. Features of Set
-
Do not store in the order in which they are saved, according to their specific order
-
HashSet internal elements sorted by Hashcode value
-
The element cannot be Hongfu
9. ArrayList automatically increase or decrease the element's strategy (learn)
The internal implementation of ArrayList uses an array, if the number of elements is less than 10, the array size is 10, if it is greater than 10, then the original length + half of the original length
10. Map (Learn)
-
Saving data in the form of key-value pairs
-
Example: Student number and name
-
When you save an element, the value is overwritten if key is the same
-
Key is unique and does not allow duplication
11. Iteration
Iterator ITR = C.iterator (); while (Itr.hasnext ()) {Itr.next ();}
2, Automatic disassembly box (learn)
Autoboxing/autounboxing
| Basic Type |
Package Type |
| Byte |
Byte |
| Short |
Short |
| Int |
Integer |
| Long |
Long |
| Float |
Float |
| Double |
Double |
| Char |
Character |
| Boolean |
Boolean |
Boolean digit = Character.isdigit (' 4 '); SYSTEM.OUT.PRINTLN (digit); Boolean letter = Character.isletter ('! '); SYSTEM.OUT.PRINTLN (letter);
3. JDK Enhanced for loop (learn)
for (Object str:list) {System.out.println (str);} for (int i = 0; I<list.size (); i++) {String str = (string) list.get (i); System.out.println (str);}
4. Generic type (Master)
list<string> list = new arraylist<string> () List.add ("AAA"); List.add (12);//error, type mismatch
5. Differences between iterator and for in iterations
-
Iterator iteration, the object of iteration has only one time;
-
For is not this start, repeat several times can.
Day191, list another subclass--linkedlist
| subclass |
Add |
Delete |
|
check |
| ArrayList |
low |
low |
high |
High |
| linkedlist |
high |
high |
low |
low |
-
The physical structure, the bottom of the ArrayList is an array, and the bottom of the LinkedList is the linked list.
-
Arrays: Fixed number of elements, continuous space
-
Linked list: The number of elements is not fixed, space is not continuous
-
Functional angle: Queue (heap), stack, tree (Learn)
-
Queue: Normal mode, FIFO (First Out)
-
Stack: LIFO, * * * Clip mode (last in first out)
-
Tree: Ordered binary tree, in a branch, the left node is the smallest, the right node is the largest.
-
Push: Pressed into the stack
-
Pop: The top element of the stack pops up (the last to come in to the eject)
-
ArrayList Why are there two remove methods?
A: Remove (object o) is collection, and remove (int index) is a new addition to the subclass because ArrayList is based on an array, so the subscript is possible.
2, array of common methods 1, two-way search
Premise: The array must be ordered
Arrays.binarysearch (Arrays,key)
2. Array conversion to List
List aslist = Arrays. Aslist (1,2,3,4,5);
3. variable parameter type ... param (learn)
Mutable parameters are implemented in an array, so it is not possible to override the method with an array as a formal parameter.
3. Sorting
Ideas:
Class Student implements comparable<student> {private int id; private String name; public int compareTo (Student o) {return this.id-o.id; }}
Class Studentcomparator implements comparator<student>{public int compare (Student O1, Student O2) { return o1.id-o2.id; }}...... comparator<student> Comparator = new Studentcomparator (); Collections.sort (List,comparator);
Weekend Homework Tips
Convert a character to a number
For example, converting ' 1 ' to shaping 1
int a = integer.valueof (' 1 ' + "")
So we can turn it into 1 smoothly.
Common methods
-
Method of CharAt () string
String name. CharAt (index) to remove characters from the string
-
Collections.frequency (Collection C, Object O)
Returns the number of elements in the specified collection that are equal to the specified object.
Java Learning Note (2015.7.27~7.31)