简体   繁体   English

检查 arrays 的第一个元素是否在数组中

[英]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.

相关问题 如何检查数组中的元素是否在另一个数组中重复。 所有这些数组都在多维数组中? - How to check if an element from an array is being repeated in another array. All these arrays are inside of a Multidimensional array? 检查 JAVA 中二维数组的第一个元素 - Check first element on a 2D array in JAVA 检查数组的第一个元素是否必须唯一 - Check first element of the array needs to be unique 根据int数组的第一个和第二个元素对int数组的数组列表进行排序 - sorting an array list of int arrays in terms of the first and the second element of the int arrays 数组-检查对象是否为数组 - Arrays - check if object is an array 有效删除Java中arraylist中每个数组的第一个元素 - Efficiently removing the first element of every array inside an arraylist in Java 如何在Java中检索List内的List的第一个和第二个元素? - How to retrieve first and 2nd element of List inside Array in Java? 在数组中查找与用户输入匹配的第一个元素并在 2 个二维数组之间打印该位置 - Finding the first element in an array that matches users input and printing that location between 2 two dimensional arrays 完成数组的第一个元素 - Finalize first element of an array 检查二维数组中单个数组的长度是否相等的有效方法 - Efficient way to check if individual arrays inside a 2-d array have equal lengths
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM