数组的测试

/*
 * 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();


   }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值