[英]check if the first element of arrays inside an array
int[][] myarray =
{ {1,0},
{3,2},
{0,1},
{2,3}
};
in HashMap i can use containsKey(i)or,containsValue(i) to check if i was used;在 HashMap 中,我可以使用 containsKey(i)or,containsValue(i) 来检查我是否被使用; is it possible to do the same with array?
可以对数组做同样的事情吗? i mean to check if in myarray i1 values z
我的意思是检查 myarray i1 中的值 z
i1 == the group of the first elements of each array inside myarray
i1 ==
myarray
中每个数组的第一个元素的组
in my example {1,3,0,2}在我的例子中 {1,3,0,2}
if myarray[:,0] = 2
print("Numbers match")
As far as I understood your question, you want to check if the first element of every inner array is unique or not.据我了解您的问题,您想检查每个内部数组的第一个元素是否唯一。
A simple solution is to loop through the outer array, access the first element of the inner array, and do the comparison with the new value.一个简单的解决方案是循环遍历外部数组,访问内部数组的第一个元素,然后与新值进行比较。
Edit: create a small method alreadyPresent()
that returns a boolean value after searching.编辑:创建一个小方法
alreadyPresent()
,它在搜索后返回 boolean 值。
if (aleadyPresent(newValue)){
print("Value already present")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.