This website uses Cookies. Click Accept to agree to our website's cookie use as described in our Privacy Policy. Click Preferences to customize your cookie settings.
You can trim spaces from a text using trim() method of String class.
public class StringTrimJava { public static void main(String[] args) {
String str = " welcome to helloworld java! "; System.out.println(str);
System.out.println(str.trim()); } } Out...