Arrays of Java classes

I. Overview

  Such java.util.Arrays comprises various methods for manipulating arrays. Such as sorting and searching, etc., all of its methods are static method call is very convenient.

Second, the method of operation of the array

  •  public static Sting toString (int [] a): Returns a string representation of the contents of an array
  •     public static void sort (int [] a): the specified int type array into ascending numerical order.

  Demo1:

. 1  public  static  void main (String [] args) {
 2      // define array int 
. 3      int [] = {2,34,35,4,657,8,69,9 ARR };
 . 4      // print array, the output address value 
5      System.out.println (ARR); // [2ac1fdc4 the I @
 . 6      // array contents into a string 
. 7      string = S of Arrays.toString (ARR);
 . 8      // print string, outputting content 
. 9      System.out.println (S); // [2, 34 is, 35,. 4, 657,. 8, 69,. 9] 
10 }

  Demo2:

. 1  public  static  void main (String [] args) {
 2      // define array int 
. 3      int [] = {24 ARR,. 7,. 5, 48,. 4, 46 is, 35,. 11,. 6, 2 };
 . 4      the System.out .println ( "front sort:" + of Arrays.toString (ARR)); // before ordering: [24, 7, 5, 48, 4, 46, 35, 11, 6,2]
 5      // ascending order 
. 6      Arrays, .sort (ARR);
 7      ( "the sort:" + of Arrays.toString (ARR)) System.out.println; // sorted: [2, 4, 5, 6, 7, 11, 24, 35, 46 48] 
8 }

 

Guess you like

Origin www.cnblogs.com/niujifei/p/11409442.html
Recommended