Show $\mathbb{E}(X) = \int_0^{\infty} (1-F_X(x)) \, dx$ for a continuous random variable $X \geq 0$

If $X$ is a continuous random variable with density $f_X$ and taking non-negative values only, how do I show that $$\mathbb{E}(X)=\int_0^{\infty}[1-F_X(x)]dx$$ whenever this integral exists?


Another hint: $$ \mathbb EX=\int_{x=0}^\infty xf_X(x)\,dx =\int_{x=0}^\infty\left(\int_{y=0}^x 1\,dy\right)f_X(x)\,dx =\int_{x=0}^\infty\left(\int_{y=0}^x f_X(x)\,dy\right)\,dx $$ Now interchange the order of integration.

(This is @saz's argument specialized to the case where $X$ has a density. You've probably been interchanging order of integration since forever, but Tonelli's theorem justifies why it's legal in this calculation.)


Hint: By Tonelli's theorem,$$\mathbb{E}X = \int X \, d\mathbb{P}= \int \left(\int_{(0,\infty)} 1_{[0,X)}(t) \, dt \right) \, d\mathbb{P} = \int_{(0,\infty)} \mathbb{P}(X > t) \, dt.$$

Hint: Assuming that $X$ has a density $f$, we have

$$\mathbb{E}X = \int_0^{\infty} x \cdot f(x) \, dx.$$

Now use integration by parts and $-f(x) = \frac{d}{dx} (1-F(x))$ where $F(x) := \mathbb{P}(X \leq x)$.