Recently do project to use arrays class, here tidy up, hope everybody can master arrays.
1.Arrays class overview
A tool class that operates on an array.
Provides sorting, lookup, and other functions.
2. Member Methods
public static String toString (int[] a)
public static void sort (int[] a)
public static int BinarySearch (int[] a,int value)
package com;
Import Java.util.Arrays;
/**
* Arrays class overview and Common methods
* tool classes for manipulating arrays.
* provides a sort, lookup and other functions.
* Member Method
* Public static string toString (int[] a) converts an array of type int to a string
* public static void sort (int[) A to sort the array, internally using the quick sort * Public static int BinarySearch (int[] a,int key) Two-point lookup method
* @author Hu Weiwei
*
* * Public
class Arraysdemo {public
static void Main (string[] args) {
int[] array = {3,44,2,546,74};
public static string ToString (int[] a) converts an array of type int to a string
System.out.println (arrays.tostring (array));//[3, 44, 2, 546)
//public static void sort (int[] a) to sort the array, internally using a quick sort
arrays.sort (array);
System.out.println (arrays.tostring (array));//[2, 3,, 546]
//public static int BinarySearch (int[) a,int key) Binary lookup Method
int index = arrays.binarysearch (array, 5);
SYSTEM.OUT.PRINTLN (index);//-3
}
}
Thank you for reading, I hope to help you, thank you for your support for this site!