Common functions for Java arrays

Source: Internet
Author: User

1 ImportJava.util.*;2 classarray index {3      Public Static voidMain (String args[]) {4           //tools for use in arrays: Arrays5           int[] arr = {1,2,3,4};6           //finds if there is a number in the array7           intnum = 3;8           //If you have one, print the corresponding index9           intresult =Arrays.binarysearch (arr,num);TenSystem.out.println ("the corresponding index value is as follows:"); One System.out.println (result); A  -System.out.println ("Ascending order is as follows:"); -           int[] arr1 = {6,4,5,2}; the Arrays.sort (arr1); -            for(inti:arr1) - System.out.println (i); -            +System.out.println ("Sort the array in reverse order as follows:"); -Arraylist<integer> list2=NewArraylist<integer>(); +            for(inti=1;i<=5;i++){ A List2.add (i); at                 } - Collections.reverse (list2); -           //list2.size (); Indicates the length of the array -            for(inti:list2) - System.out.println (i);  -       } in}

Common functions for Java 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.