Java applet 3Arrays (2015-8-27)

Source: Internet
Author: User

Import Java.util.Arrays;
public class arraysdemo{
public static void Main (string[] args) {
int [] arraysrc1={1,3,4,5,6,2};
Copy data, no value default 0;
int [] arraydes1=arrays.copyof (arraysrc1,10);
for (int i=0;i<arraydes1.length;i++) {
System.out.print (arraydes1[i]+ "");
}

Copies the specified range of data within the specified array, subscript 2-subscript 4,4-2=2 number;
int [] Arraydes2=arrays.copyofrange (arraysrc1,2,4);
for (int i=0;i<arraydes2.length;i++) {
System.out.print (arraydes2[i]+ "");
}
The comparison of the array. Compares the specified array with the original array is not the same, exactly as true;

int [] arraysrc2={1,3,4,5,6,2};
Boolean flag=arrays.equals (ARRAYSRC1,ARRAYSRC2);
SYSTEM.OUT.PRINTLN (flag);
Array padding

int [] arraydes3=new int[10];
All data in the array is populated with 10;
Arrays.fill (arraydes3,10);
Specify a range fill, subscript 1-subscript 5, altogether 5-1 = 4 numbers are filled;
Arrays.fill (arraydes3,1,5,10);
for (int i=0;i<arraydes3.length;i++) {
System.out.print (arraydes3[i]+ "");
}
Sorts the array, from small to large.

Arrays.sort (ARRAYSRC1);
for (int i=0;i<arraysrc1.length;i++) {
System.out.print (arraysrc1[i]+ "");
}
The method of binary method finding

int Index=arrays.binarysearch (arraysrc1,5);
System.out.print (index);

Copy an array using the methods of the System class

int [] arraydes5=new int[10];
System.arraycopy (arraysrc1,0,arraydes5,2,5);
for (int i=0;i<arraydes5.length;i++) {
System.out.print (arraydes5[i]+ "");
}
}
}

Java applet 3Arrays (2015-8-27)

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.