Java Learning: variable parameters

variable parameter

Variable parameters: it is a new feature that appears after JDK1.5

Use the premise:

  • When the process parameter list data type has been determined, but the number of uncertain parameters, variable parameters can be used.

Using the format: definition method used

  • Modifier return type method name (variable name data type ...)} {

The principle of variable parameters:

  • Underlying variable parameter is an array, depending on the number of parameters passed, it creates an array of different lengths, to store these parameters
  • The number of parameters passed, and may be 0 (no transmission), a plurality of 1,2, ...

 

Variable parameters Note:

  1. A method parameter list, only one variable parameter
  2. If there are multiple parameters of the method, the variable parameters must be written at the end of the parameter list
Method static void public (B String, Double C, D int, int ... A) {} 
// special variable parameters (ultimate) written 
public static void Method (Object obj ...)} { 
the Collections collection tools the method 
java.util.Collections is a collection of tools for the collection operation. Part follows: 
    public static <T> void Sort (List <T> List, Comparator <Super T?>): The set of elements according to an specified rules. 
    
    Comparator and Comparable differences 
        Comparable: own (this) and others (parameters) comparison, we need to implement the Comparable interface, rewrite the rules of comparison compareTo method 
        Comparator: find the equivalent of a third-party referee compare two 
        
    collation of Comparator: 
        O1 -o2: ascending

 

Guess you like

Origin www.cnblogs.com/cainiao-chuanqi/p/11223173.html