如何确定我的int []的ArrayList是否包含int []

编程入门 行业动态 更新时间:2024-10-19 22:43:35
本文介绍了如何确定我的int []的ArrayList是否包含int []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个ArrayList包含int[].

假设Arrays.equals(int[], (a value in the arrayList)) = true

为什么我做arrayOfInts.contains(int[])这是假的?

我认为是(int[] == (a value in the arrayList)) = false的相同原因,但我应该得到此错误吗?

I assume it is because of the same reason that (int[] == (a value in the arrayList)) = false but should I be getting this error?

我可以以某种方式纠正它吗?

Can I correct it somehow?

TL; DR:我可以将Arraylist.contains()用于int []

TL;DR: Can I use Arraylist.contains() for int[]

答案(如果将来有人在这里搜索,这是我作为解决方案编写的比较代码):

ANSWER (if anyone searches this in the future here's the comparison code I made as a solution):

private boolean arraylistContains(int[] comparison, ArrayList<int[]> arrayListToCompare){ for(int[] values: arrayListToCompare){ if (Arrays.equals(comparison, values)){ return true; } } return false; }

推荐答案

数组列表仅存储对数组的引用,而不存储其内容,因此,如果列表包含确切的引用,则contains()仅能说到您输入的数组.它不评估数组的内容.

A list of arrays stores only the references to the arrays, not their content, therefore contains() is only able to say, if the list contains the exact reference to the array you input. It doesn't evaluate the contents of the array.

如果需要检查列表是否包含具有特定值的数组,则必须遍历列表并使用 Arrays.equals(arr1,arr2).

If you need to check, if the list contains an array with specific values, you will have to iterate over the list and use Arrays.equals(arr1, arr2).

更多推荐

如何确定我的int []的ArrayList是否包含int []

本文发布于:2023-11-12 12:10:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581466.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:int   ArrayList

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!