如何在Java中覆盖数组的等于? [英] How to overide equals for array in Java?

查看:102
本文介绍了如何在Java中覆盖数组的等于?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望覆盖int []数组的equals。这样以下就是真的

I wish to overide the equals for int[] arrays. Such that the following will be true

int[] a = {1,2,3};
int[] b = {1,2,3};
System.out.println(a.equals(b));

有没有办法做到这一点?

Is there a way to do that?

推荐答案

覆盖 int [] 等于方法是不可能的并没有必要。您希望的功能可以通过使用 Arrays.equals(int [],int [])

Overriding the equals method of int[] is both not possible and not necessary. The functionality you desire can be achieved by using Arrays.equals(int[], int[]).

int[] a = {1,2,3};
int[] b = {1,2,3};
System.out.println(Arrays.equals(a, b));

这篇关于如何在Java中覆盖数组的等于?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆