1. Examples of polymorphic and dynamic bindings help to understand
1 Public classTest {2 Public Static voidMain (string[] args) {3 NewA ();4 NewB ();5 }6 }7 8 classA {9 Public inti = 7;Ten One PublicA () { ASetI (20); -System.out.println ("The number of I in A is" +i); - } the - Public voidSetI (inti) { - This. i = 2 *i; - } + - } + A classBextendsA { at PublicB () { -System.out.println ("The I in B is" +i); - } - - Public voidSetI (inti) { - This. i = 3 *i; in } -}
Output to
The number of I in Ais 60
View Code
Usage of the 2.ArrayList class [Object list/object array]
The ArrayList class contains methods that have +arraylist ()/+add ()/+add (Index,inti)/+clear/+contains/+get (Intdex)/+indexof (object)/+isempty () /+remove ()/+set (Index,inti)
Creation mode arraylist<string> list = new arraylist<> ();
The ArrayList class can use traversal, which is the same as the array;
Create a list of objects from an array {
string[] array = new STRING[5];
arraylist<string> list = new Arraylist<> (arrays.aslist (array)); This is done using the Aslist method of the arrays class for replication.
}
In turn, create an array from the object list {
arraylist<string> list = new arraylist<> ();
String[] B = new string[list.size ()];
List.toarray (b);
}
If the array contains numeric objects, it can be sorted as follows
Double [] array = {1.2,1,3,5.3,0.3};
Arrays.sort (array);
The same for object list
arraylist<string> list = new Arraylist<> (arrays.aslist (array));
Java.util.Collections.sort (list);
There are many other uses of collections which are very convenient. For example Collections.max (list)/collections.min (list)/collections.shuffle (list)//scrambled
2016/5/29 Study Record