Skip to content

Instantly share code, notes, and snippets.

@adityaditiket
Created September 1, 2020 02:51
Show Gist options
  • Save adityaditiket/0de800ee9e8903dc4cd6604b3dec3478 to your computer and use it in GitHub Desktop.
Save adityaditiket/0de800ee9e8903dc4cd6604b3dec3478 to your computer and use it in GitHub Desktop.
replace multiple white space in java
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
String name = " hello there ";
String after = name.trim().replaceAll(" +", " ");
System.out.println("after="+after );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment