2016/5/29 Study Record

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.