如何检查两个数组列表在相同位置的相同内容 [英] How to check two array list are same content in same position

查看:50
本文介绍了如何检查两个数组列表在相同位置的相同内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查两个数组列表中的值及其位置是否相同?

示例:

//这些应该不相等.ArrayListlistA = {"a", "b", "c"}ArrayListlistB = {"b", "c", "a"}

在此示例中,元素在两个数组列表中的位置不同,因此返回 false..如何在不使用for循环

的情况下检查相同位置的相同值

我想要这个结果.

//这些应该是相等的.ArrayListlistA = {"a", "b", "c"}ArrayListlistB = {"a", "b", "c"}

这个类型的数组列表然后返回true,因为两个数组中的值和位置相同..

解决方案

使用

return listA.equals(listB);

<块引用>

当且仅当指定的对象也是一个列表时返回真,两者都是列表具有相同的大小,并且所有对应的元素对都在这两个列表是相等的.

How to check value and its position are same in 2 array list wi?.

Example:

//These should be not equal.
ArrayList<String> listA = {"a", "b", "c"}
ArrayList<String> listB = {"b", "c", "a"}

In this example element are not same position in both array list so return false.. How to check same value in same position without using for loop

I want to expected result this if.

    //These should be equal.
ArrayList<String> listA = {"a", "b", "c"}
ArrayList<String> listB = {"a", "b", "c"}

this type array list then return true because the value and position are same in both array..

解决方案

use

return listA.equals(listB);

Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal.

这篇关于如何检查两个数组列表在相同位置的相同内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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