Older Dick Silk Self-study note--java 0 basics to rookie--028

Source: Internet
Author: User

Generics, for-loop enhanced applications, static import, variable parameters, Aslist ()

1. Generic type

The data type is constrained, the format is < data type, such as:arraylist<int> alist=new arraylist<int> ();

Generic wildcard characters:<?> object and any class, <?extends e> E class and its subclasses, <?super E> class and its parent class.

2. For loop Enhanced application

1 arraylist<string> alist=new arraylist<string>(); 2 alist.add ("a"); 3 alist.add ("B"); 4  for (String str:alist) {5    System.out.println (str); 6 }78// output: A, b

3. Static Import

Format: Import static package name ... Class name. method name;.

Caveats: You can import directly to the level of a method, but the method must be static.

1 Import Static Java.lang.Math.abs; 2 3  Public class fin{4      Public Static void Main (string[] args) {5         SYSTEM.OUT.PRINTLN (ABS ( -1)); 6     }7 }

4. Variable parameters

Variable arguments (actually an array) can be used when the number of parameters is indeterminate.

Format: "Data type ..." variable name, such as: public static int Liverpool (int ... a)

Note: If a method has more than one parameter, the mutable parameter must be the last.

5, Aslist ();

1 string[] strarray={"A", "B", "C"}; 2 list<string> strlist=array.aslist (strarray); 3  for (String str:strlist) {4    System.out.pringln (str); 5 }67// output: A, B, C

Older dick Silk self-study note--java 0 basics to rookie--028

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.