Java Arrays class detailed and instance code _java

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.