If $x_1,x_2,\ldots,x_n$ are arbitrary numbers from the interval $[0,2]$, prove that
$$\sum_{i=1}^n\sum_{j=1}^n|x_i-x_j|\le n^2$$When is the equality attained?
1. **Assume the order of the numbers**: Without loss of generality (WLOG), let \( x_1 \leq x_2 \leq \dots \leq x_n \). This ordering helps simplify the analysis of the absolute differences.

2. **Analyze the sum of absolute differences**: We need to evaluate the double sum \( \sum_{i=1}^n \sum_{j=1}^n |x_i - x_j| \). By the ordering assumption, \( x_i \leq x_j \) for \( i \leq j \), so \( |x_i - x_j| = x_j - x_i \).

3. **Count the appearances of each \( x_i \)**: 
   - \( x_n \) appears positively \( 2(n-1) \) times (once for each \( x_i \) where \( i < n \) and once for each \( x_j \) where \( j < n \)).
   - \( x_{n-1} \) appears positively \( 2(n-2) \) times and negatively twice (once for each \( x_i \) where \( i < n-1 \) and once for each \( x_j \) where \( j < n-1 \)).
   - Following this pattern, the coefficient of \( x_i \) in the sum is \( 2(n-i) \).

4. **Express the sum in terms of \( x_i \)**:
   \[
   \sum_{i=1}^n \sum_{j=1}^n |x_i - x_j| = 2(n-1)x_n + 2(n-3)x_{n-1} + \dots + 2(1-n)x_1
   \]

5. **Simplify the expression**:
   \[
   = 2 \left[ (n-1)x_n + (n-3)x_{n-1} + \dots + (1-n)x_1 \right]
   \]

6. **Bound the differences**: Since \( x_i \in [0, 2] \), the maximum difference \( x_n - x_1 \leq 2 \). Therefore, each term \( (x_i - x_j) \leq 2 \).

7. **Sum the coefficients**:
   - For \( n = 2k+1 \) (odd \( n \)):
     \[
     2 \left[ (n-1) + (n-3) + \dots + 1 \right] = 2 \left[ 2k + 2(k-1) + \dots + 2 \right] = 4(k + (k-1) + \dots + 1) = 4 \frac{k(k+1)}{2} = 2k(k+1)
     \]
     Since \( n = 2k+1 \), we have:
     \[
     2k(k+1) < (2k+1)^2 = n^2
     \]

   - For \( n = 2k \) (even \( n \)):
     \[
     2 \left[ (n-1) + (n-3) + \dots + 1 \right] = 2 \left[ 2k-1 + 2(k-1) + \dots + 1 \right] = 4(k^2) = n^2
     \]

8. **Conclusion**: The sum \( \sum_{i=1}^n \sum_{j=1}^n |x_i - x_j| \leq n^2 \). Equality is achieved when \( n = 2k \) and \( x_1 = x_2 = \dots = x_k = 0 \) and \( x_{k+1} = x_{k+2} = \dots = x_n = 2 \).

The final answer is \( \boxed{ \sum_{i=1}^n \sum_{j=1}^n |x_i - x_j| \leq n^2 } \)