code: public static boolean isWitnessCommitment(Script script) {
          List<ScriptChunk> chunks = script.chunks;
          if (chunks.size() < 2)
              return false;
          if (!chunks.get(0).equalsOpCode(ScriptOpCodes.OP_RETURN))
              return false;
          byte[] chunkData = chunks.get(1).data;
          if (chunkData == null || chunkData.length != 36)
              return false;
          if (!Arrays.equals(Arrays.copyOfRange(chunkData, 0, 4), SEGWIT_COMMITMENT_HEADER))
              return false;
          return true;
      }
docs: Returns whether this script matches the pattern for a segwit commitment (in an output of the coinbase
  transaction).