IntStreamを用いて2次元アレイ内のアレイをチェック

ゲイブガレオン:

私は、座標のセットが(かどうかを確認しているよcoor)座標の配列内に存在します(coorArray)。私はそれがで検索できるように、2次元配列を連結する方法の他の記事で見てきたIntStream唯一のためint、私は確かにどのようにそれは私の問題の方に翻訳していませんよ。お手伝いありがとう!

例えばアレイ。

int[][] coorArray = {{1,2},{2,2},{3,0}};
int[] coor = {1,2};
Qでのストレンジャー:

前年比では使用することができstream().anyMatch()、このチェックを実行するには:

int[][] coorArray = {{1,2},{2,2},{3,0}};
int[] coor = {1,2};
boolean exist = Arrays.stream(coorArray).anyMatch(e -> Arrays.equals(e, coor));
System.out.println("exist = " + exist);  

出力:

exist = true


座標がない場合にそうでない場合、入力配列内に存在します。

int[][] coorArray = {{4,2},{2,2},{3,0}};
int[] coor = {1,2};
boolean exist = Arrays.stream(coorArray).anyMatch(e -> Arrays.equals(e, coor));
System.out.println("exist = " + exist);

出力:

exist = false

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=187857&siteId=1