trim all spaces in java code example Example: how to remove all whitespace from string java st = st.replaceAll("\\s+","")