An array of related functions

1, using System.arraycopy () function copies the array

public  class ArrayCopyDemo {
     public  static  void main (String [] args) {
         int Arr1 [] = new new  int [] {. 1, 2,. 3,. 4,. 5 };
         int Arr2 [] = new new  int [] {. 9,. 8, . 7,. 6,. 5,. 4,. 3 }; 
        System.arraycopy (Arr1, 0, Arr2, 0,. 3 ); // static type methods, directly call the class name.
        // copy source array index starts from 03 array elements to the object, from a starting position 0 under standard storage. 
        for ( int I = 0; I <Arr1.length; I ++ ) 
            of System.out.print (Arr1 [I]); 
        System.out.println (); 
        for ( int0 = J; J <Arr2.length; J ++ ) 
            of System.out.print (Arr2 [J]); 
        System.out.println (); // copy number of array elements must not exceed the length of the destination array. 
    } 
}

2, Arrays.sort to sort the array

 

package SortDemo;

import java.util.*;

public class SortDemo {
    public static void main(String[] args) {
        int Arr[] = new int[] { 10, 21, 4, 9, 8, 3, 34, 99 };
        Arrays.sort(Arr);
        for (int i = 0; i < Arr.length; i++) {
            System.out.print(Arr[i]);
            System.out.print("\t");
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/zhai1997/p/11260701.html