how to delete unnecessary spaces with java 8? : <p>can anyone help me to find a solution to this problem in Java 8:</p>

<p>A string of characters is composed of multiple spaces is given to you. You must remove all unnecessary spaces by writing an algorithm.</p>

<p>Entry: String containing a sentence.
Output: String containing the same sentence without unnecessary spaces.</p>

<p>Example:
For the following entry: "I (3spaces)  live (3spaces) on (3spaces) earth."
The output is: "I live on earth."</p>
