java Arrays class details and example code
- 2020-05-10 18:16:15
- OfStack
Recently, I used Arrays class in my project. I hope you can master Arrays.
1. Arrays class overview
utility class that operates on arrays.
provides sorting, searching and more.
2. Member method
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
* A utility class that operates on an array.
* It provides sorting, searching and other functions.
* Members of the method
* public static String toString(int[] a) will int An array of type is converted to a string
* public static void sort(int[] a) To sort the array, the internal use of quick sort
* public static int binarySearch(int[] a,int key) 2 A method to determine points
* @author Xu Weiwei
*
*/
public class ArraysDemo {
public static void main(String[] args) {
int[] array = {3,44,2,546,74};
//public static String toString(int[] a) will int An array of type is converted to a string
System.out.println(Arrays.toString(array));//[3, 44, 2, 546, 74]
//public static void sort(int[] a) To sort the array, the internal use of quick sort
Arrays.sort(array);
System.out.println(Arrays.toString(array));//[2, 3, 44, 74, 546]
//public static int binarySearch(int[] a,int key) 2 A method to determine points
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 of this site!