/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package newpackage;
import java.util.Arrays;
/**
*
* @author Administrator
*/
public class 测试数组方法 {
public static void main(String args[]) {
System.out.println("****创建数组且利用复制的方式*****");
int a[] = {3, 5, 1, 6, 0, 8, 7, 2, 4};
int b[] = Arrays.copyOfRange(a, 3, 6);
int c[] = Arrays.copyOf(a, a.length);
for (int i : a) {
System.out.print(i + ",");
}
System.out.println();
for (int i : b) {
System.out.print(i + ",");
}
System.out.println();
for (int i : c) {
System.out.print(i + ",");
}
System.out.println();
System.out.println("*******对数组排序,其中c为部分排序*****");
Arrays.sort(a);
Arrays.sort(b);
Arrays.sort(c, 3, 6);
for (int i : a) {
System.out.print(i + ",");
}
System.out.println();
for (int i : b) {
System.out.print(i + ",");
}
System.out.println();
System.out.println(" **数组c只是4,5,6三位排序了** ");
for (int i : c) {
System.out.print(i + ",");
}
System.out.println();
System.out.println("*************************************");
System.out.println("******搜 索 数 组 中 指 定 的 值******");
int a6 = Arrays.binarySearch(a, 6);
System.out.print(a6);
System.out.println();
System.out.println("**搜索数组a中是否有6,且判断6所在的位置**");
System.out.println("*****比较两个数组是否相等**********");
boolean f = Arrays.equals(a, c);
System.out.println(f);
System.out.print((f?"a=c":"a!=c"));//三目运算。
System.out.println();
}
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package newpackage;
import java.util.Arrays;
/**
*
* @author Administrator
*/
public class 测试数组方法 {
public static void main(String args[]) {
System.out.println("****创建数组且利用复制的方式*****");
int a[] = {3, 5, 1, 6, 0, 8, 7, 2, 4};
int b[] = Arrays.copyOfRange(a, 3, 6);
int c[] = Arrays.copyOf(a, a.length);
for (int i : a) {
System.out.print(i + ",");
}
System.out.println();
for (int i : b) {
System.out.print(i + ",");
}
System.out.println();
for (int i : c) {
System.out.print(i + ",");
}
System.out.println();
System.out.println("*******对数组排序,其中c为部分排序*****");
Arrays.sort(a);
Arrays.sort(b);
Arrays.sort(c, 3, 6);
for (int i : a) {
System.out.print(i + ",");
}
System.out.println();
for (int i : b) {
System.out.print(i + ",");
}
System.out.println();
System.out.println(" **数组c只是4,5,6三位排序了** ");
for (int i : c) {
System.out.print(i + ",");
}
System.out.println();
System.out.println("*************************************");
System.out.println("******搜 索 数 组 中 指 定 的 值******");
int a6 = Arrays.binarySearch(a, 6);
System.out.print(a6);
System.out.println();
System.out.println("**搜索数组a中是否有6,且判断6所在的位置**");
System.out.println("*****比较两个数组是否相等**********");
boolean f = Arrays.equals(a, c);
System.out.println(f);
System.out.print((f?"a=c":"a!=c"));//三目运算。
System.out.println();
}
}