Java starts from zero 10 (common methods for arrays class arrays)

Source: Internet
Author: User

First, arrays class common methods

Second, a simple example
 PackageCom.pb.demo1;Importjava.util.Arrays;/** Several common methods in Arrays tool class * 1.copyof * 2.toString * 3.equals * 4.sort * 5.fill * 6.binarySearch*/ Public classArraystest { Public Static voidMain (string[] args) {String [] arry1={"Beijing", "Shanghai", "Chongqing", "Shenzhen"}; String [] Arry2=arrays.copyof (Arry1, 4); //copy copyofSystem.out.println ("Arry2 is:" +arrays.tostring (Arry2)); //Compare equalsSystem.out.println ("Arry1 and Arry2 are equal:" +arrays.equals (Arry1, Arry2)); //sort the Arry1Arrays.sort (Arry1); //toStringSystem.out.println ("The value of the sorted Arry1:" +arrays.tostring (arry1)); //whether Arry1 is equal to Arry2 after sorting equalsSystem.out.println ("Arry1 and Arry2 are still equal after sorting" +arrays.equals (Arry1, Arry2)); //Filling FillArrays.fill (Arry2, "Guangzhou"); System.out.println ("The value of Arry2 after padding:" +arrays.tostring (Arry2)); //Query BinarySearch If the array has been sorted before it can be usedSystem.out.println ("Chongqing's position in Arry1:" +arrays.binarysearch (Arry1, "Chongqing"))); }}

Results:

Arry2 is: [Beijing, Shanghai, Chongqing, Shenzhen]
Arry1 and Arry2 are equal: true
Value of the sorted arry1: [Shanghai, Beijing, Shenzhen, Chongqing]
Whether Arry1 and Arry2 are still equal after sorting false
Value after padding arry2: [Guangzhou, Guangzhou, Guangzhou]
Chongqing's location in Arry1:3

Java starts from zero 10 (common methods for arrays class arrays)

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.