code: public static boolean isP2WH(Script script) {
          List<ScriptChunk> chunks = script.chunks;
          if (chunks.size() != 2)
              return false;
          if (!chunks.get(0).equalsOpCode(OP_0))
              return false;
          byte[] chunk1data = chunks.get(1).data;
          if (chunk1data == null)
              return false;
          if (chunk1data.length != SegwitAddress.WITNESS_PROGRAM_LENGTH_PKH
                  && chunk1data.length != SegwitAddress.WITNESS_PROGRAM_LENGTH_SH)
              return false;
          return true;
      }
docs: Returns true if this script is of the form {@code OP_0 <hash>}. This can either be a P2WPKH or P2WSH scriptPubKey. These
  two script types were introduced with segwit.