Java Arrays Class Learning

Source: Internet
Author: User

The Java.util.Arrays class makes it easy to manipulate an array, and all of the methods it provides are static.

Has the following features:

(1) Assigning a value to an array: through the fill method.

(2) sorting an array: By the sort method , in ascending order.

(3) Compare arrays: compares the values of the elements in an array by the Equals method to be exactly equal.

(4) Finding array elements: The binarysearch method can be used to perform binary lookups of sorted arrays (requires that the original array must be ordered).

Importjava.util.Arrays; Public classMain { Public Static voidMain (string[] args) {int[]arr=New int[10]; Arrays.fill (arr,5);                System.out.println (arrays.tostring (arr)); int[] Nums = {6,1,5,9,3,5,7,2,3,9};        Arrays.sort (Nums);                System.out.println (arrays.tostring (nums)); int[] nums1 = {6,1,5,9,3,5,7,2,3,9}; int[] Nums2 = {6,2,5,9,3,5,7,2,3,9}; int[] Nums3 = {6,1,5,9,3,5,7,2,3,9};        System.out.println (Arrays.equals (NUMS1, NUMS2));                System.out.println (Arrays.equals (NUMS1, NUMS3)); intXb=arrays.binarysearch (Nums, 5);    SYSTEM.OUT.PRINTLN (XB); }}

Note that the Nums array has been sorted before the program uses binary lookup.

Java Arrays Class Learning

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.