  In this paper, we extend the phase space of black holes enclosed by a
spherical cavity of radius $r_{B}$ to include $V\equiv4\pi r_{B}^{3}/3$ as a
thermodynamic volume. The thermodynamic behavior of Schwarzschild and
Reissner-Nordstrom (RN) black holes is then investigated in the extended phase
space. In a canonical ensemble at constant pressure, we find that the
aforementioned thermodynamic behavior is remarkably similar to that of the
anti-de Sitter (AdS) counterparts with the cosmological constant being
interpreted as a pressure. Specifically, a first-order Hawking-Page-like phase
transition occurs for a Schwarzschild black hole in a cavity. The phase
structure of a RN black hole in a cavity shows a strong resemblance to that of
the van der Waals fluid. Our results may provide a new perspective for the
extended thermodynamics of AdS black holes by analogy with black holes in a
cavity.
