2013-02-02 81 views

回答

0

或者你可以寫一些像這樣:

public static double[] unite(double[]... arrays) 
{ 
    int length = 0; 
    for(double[] array: arrays) 
     length += array.length; 


    double[] united = new double[length]; 

    int pos = 0; 
    for(double[] array: arrays) { 
     System.arraycopy(array, 0, united, pos, array.length); 
     pos += array.length; 
    } 

    return united; 
} 


public static void main(String... args) { 

    double[] d1 = {0.1, 0.2}; 
    double[] d2 = {0.3, 0.4, 0.5}; 
    double[] d3 = {0.6, 0.7, 0.8, 0.9}; 
    double[] d4 = {}; 
    double[] d5 = {1.0}; 

    double[] united = unite(d1, d2, d3, d4, d5); 

    System.out.println(Arrays.toString(united)); 
}