Linearity of maximum function in expectation I was solving an exercise for a probability theory course and stumbled upon the following problem.
Given a continuous random variable $X$, and $\max(a,b) = a$ if $a > b$ and $b$ otherwise, is
$$
E[\max(X, 0)] = \max(E[X], 0)
$$
true in general?

It is not true.  A simple counterexample is letting $X \sim N(0, 1)$. Then $\max(E(X), 0) = 0$, whereas
\begin{align}
 & E(\max(X, 0)) = \int_{-\infty}^\infty \max(x, 0)\phi(x)dx = \int_0^\infty x\frac{1}{\sqrt{2\pi}}e^{-x^2/2}dx = \frac{1}{\sqrt{2\pi}} > 0.
\end{align}
In fact, using $\max(a, b) = \frac{1}{2}((a + b) + |a - b|)$, it can be seen that
\begin{align}
& E(\max(X, 0)) = \frac{1}{2}(E(X) + E(|X|)), \\
& \max(E(X), 0) = \frac{1}{2}(E(X) + |E(X)|)). 
\end{align}
Because $|E(X)| \leq E(|X|)$ for any integrable random variable $X$, it always holds that (it's also a consequence of Jensen's inequality $f(E(X)) \leq E(f(X))$ with $f(x) = \max(x, 0)$):
\begin{align}
E(\max(X, 0)) \geq \max(E(X), 0), 
\end{align}
and the strict inequality holds for any random variable such that $E(|X|) > |E(X)|$. Needless to say, there are numerous such random variables.

Assuming $E[|X|] < \infty$, as @Henry commented, a necessary and sufficient condition for $E[|X|] > |E[X]|$ is $P(X > 0) > 0$ and $P(X < 0) > 0$.  To prove it, let $X^+ = \max(X, 0)$ and $X^- = \max(-X, 0)$, then $E[|X|] = E[X^+] + E[X^-]$, $|E[X]| = |E[X^+] - E[X^-]|$.
If $P(X > 0) > 0$ and $P(X < 0) > 0$, then (by, say, Theorem 15.2(ii) of Probability and Measure) $E[X^+] > 0, E[X^-] > 0$, hence $|E[X]| = |E[X^+] - E[X^-]| < E[X^+] + E[X^-] = E[|X|]$.
Conversely, if $|E[X^+] - E[X^-]| < E[X^+] + E[X^-]$, since $|a - b| < a + b$ holds for non-negative $a, b$ if and only if $a \neq 0$ and $b \neq 0$, it follows that $E[X^+] > 0$ and $E[X^-] > 0$, which in turn requires $P(X > 0) > 0$ and $P(X < 0) > 0$.
