int matrix1 [][] = {{0, 1}, {2, 5}};
int matrix2 [][] = new int[50][50];
int[][] a = {
{1, 2, 3},
{4, 10, 6},
{7, 8, 9, 12, 13, 14, 15}
};
int b[][] = {
{1, 2},
{3, 4},
{5},
{6, 7, 8, 9}
};
Stream<Integer> entriesA = Stream.of(a).flatMapToInt(IntStream::of).boxed();
List<Integer> entriesB = Stream.of(b).flatMapToInt(IntStream::of).boxed().collect(Collectors.toList());
List<Integer> same = entriesA.filter(entriesB::contains).collect(Collectors.toList());