Arrays工具类的使用

所遇问题:
当要查找的数据在数组中有重复时,输出下标结果为不准确。
代码如下:

package practice;

import java.util.Arrays;

/**
 * 
 * @Description Arrays工具类的使用
 * @author zth Email:2945724540@qq.com
 * @version
 * @data 2021年7月12日下午6:49:32
 */
public class ArraysTest01 {
	public static void main(String[] args) {
		int[] a1 = new int[] { 1, 2, 3, 4, 5, 6 };
		int[] a2 = new int[] { 5, 4, 2, 3, 1, 6 };
		boolean isEqual = Arrays.equals(a1, a2);
		System.out.println(isEqual);
		System.out.println(Arrays.toString(a1));
		Arrays.fill(a1, 10);
		System.out.println(Arrays.toString(a1));
		Arrays.sort(a2);
		System.out.println(Arrays.toString(a2));
		int[] a3 = new int[] {34,245,564,12,54,645,64,34,23,64,89,77};
		int index=Arrays.binarySearch(a3, 64);
		System.out.println(Arrays.toString(a3));
		System.out.println(index);
	}

}

运行结果如下:

false
[1, 2, 3, 4, 5, 6]
[10, 10, 10, 10, 10, 10]
[1, 2, 3, 4, 5, 6]
[34, 245, 564, 12, 54, 645, 64, 34, 23, 64, 89, 77]
-2

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值