Using a lattice equation of state combined with the D-dimensional Tolman–Oppenheimer–Volkoff equation and the Friedmann equations, we investigate the possibility of the formation of compact objects as well as the time evolution of the scale factor and the density profile of a self-gravitating material cluster. The numerical results show that in a (2+1)-dimensional space–time, the mass is independent of the central pressure. Hence, the formation of only compact objects with a finite constant mass similar to the white dwarf is possible. However, in a (3+1)-dimensional space–time, self-gravity leads to the formation of compact objects with a large gap of mass and the corresponding phase diagram has the same structure as the one for Neutron Star. The results also show that beyond certain critical central pressure, the star is unstable against gravitational collapse, and it may end in a black hole. Analysis of space–times of higher dimensions shows that gravity has the stronger effect in 3+1 dimensions. Numerical solutions of the Friedmann equations show that the effect of the curvature of space–time increases with the increasing temperature, but decreases with the increasing dimensionality beyond D=3.