Given a string with leading and trailing spaces and we have to trim the spaces.
It is a method of String class; it returns string after removing trailing and leading spaces.
Consider the program:
Here, is a string with trailing and leading spaces and program will trim the string (remove the spaces).
import java.lang.*; public class StringTrimPrg { public static void main(String []args) { String str=" www.includehelp.com "; System.out.println("String omitting leading and trailing spaces: "+ str.trim()); } }
Output
String omitting leading and trailing spaces: www.includehelp.com
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Consider the program:
Here, is a string with trailing and leading spaces and program will trim the string (remove the spaces).
Output