Java starts from scratch (a common method of the Arrays class for arrays), and Arrays starts from scratch

Source: Internet
Author: User

Java starts from scratch (a common method of the Arrays class for arrays), and Arrays starts from scratch
I. Common Arrays Methods

Ii. Simple Example
Package com. pb. demo1; import java. util. arrays;/** several common methods in the Arrays tool class * 1. copyof * 2. toString * 3. equals * 4. sort * 5. fill * 6. binarySearch */public class ArraysTest {public static void main (String [] args) {String [] arry1 = {"Beijing", "Shanghai", "Chongqing ", "Shenzhen"}; String [] arry2 = Arrays. copyOf (arry1, 4); // copy copyof System. out. println ("arry2 is:" + Arrays. toString (arry2); // compare equals System. out. println ("is arry1 equal to arry2?" + Arrays. equals (arry1, arry2); // sort arry1 to sort Arrays. sort (arry1); // toString System. out. println ("value of arry1 after sorting:" + Arrays. toString (arry1); // after sorting, whether arry1 and arry2 are equal to equals System. out. println ("whether arry1 and arry2 are equal after sorting" + Arrays. equals (arry1, arry2); // fill in fill Arrays. fill (arry2, "Guangzhou"); System. out. println ("the value of arry2 after filling:" + Arrays. toString (arry2); // you can use System to query binarySearch only after the array has been sorted. out. println ("Location of Chongqing in arry1:" + Arrays. binarySearch (arry1, "Chongqing "));}}

Result:

Arry2 is: [Beijing, Shanghai, Chongqing, Shenzhen]
Whether arry1 and arry2 are equal: true
Value of arry1 after sorting: [Shanghai, Beijing, Shenzhen, Chongqing]
Whether arry1 and arry2 are equal after sorting is false
Value of arry2 after filling: [Guangzhou, Guangzhou]
Location of Chongqing in arry1: 3

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.