Arrays_function()

package card;

import java.util.Arrays;

public class Arrays_class {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //数组赋值方法
        int [] num1 = {1,2,3,4,5};
        int num2 [] = {1,2,3,4,6};
        int [] num3 = new int[]{12,28,33,74,15,76,27};
        //int num4 [] = new int[]{1,2,3,4,5,6,7,8,9};
        
        //.equals()方法 boolean 型,比较数组是否相等,输出结果false/true
        //boolean eq = Arrays.equals(num1, num2);
        System.out.println(Arrays.equals(num1, num2));
        
        //数组排序(升序),输出结果[12, 15, 27, 28, 33, 74, 76],.sort()方法
        //toString()  将.....转化为字符串
    
     int num3[]; Arrays.sort(num3); System.out.println(Arrays.toString(num3)); //fill 方法,结果[0, 0, 0, 0, 0] int[] num4 = {1,2,3,4,5}; Arrays.fill(num4, 0); System.out.println(Arrays.toString(num4)); //copyOf方法 int [] num5 = {1,2,3,4,5,6,7,8}; int [] tep = Arrays.copyOf(num5, 6); System.out.println(Arrays.toString(tep)); //结果[1, 2, 3, 4, 5, 6] char [] num6 ={'1','2','3','4','5'}; char [] to = Arrays.copyOf(num6, 8); //结果[1, 2, 3, 4, 5, , , ] System.out.println(Arrays.toString(to)); //binarySearch 对已排序的数组进行数据的二分法查找 int [] num7 = {12,34,26,75,45,62}; Arrays.sort(num7); System.out.println(Arrays.toString(num7)); //进行升序[12, 26, 34, 45, 62, 75] System.out.println(Arrays.binarySearch(num7, 34)); //查找结果2: 地址 0 1 2 3 4 5 System.out.println(Arrays.binarySearch(num7,77)); //查找结果-6: 地址-1 -2..-7 } }

 

posted @ 2016-07-29 15:06  me丶不是好人  阅读(157)  评论(0编辑  收藏  举报