0

Meaning of trim() function in java ?

string

15th Mar 2017, 4:27 PM
Mitesh Wadekar
Mitesh Wadekar - avatar
2 Antworten
+ 1
When applied to a string of characters, it removes the leading and trailing spaces, that is, it deletes the whitespaces at the beginning and at the end.
15th Mar 2017, 5:29 PM
Álvaro
+ 1
Basically , trim() is an inbuilt method present in java.lang of String class.Basically importing java.lang package is completely optional because it is imported by default by the compiler when ever we open a new .java file. When applied on a string , it removes starting and leading spaces of the string. For example:- String s1=" Hello Sololearn "; String s2=s1.trim(); System.out.println(s2); //s2 becomes "Hello Sololearn"
17th Sep 2020, 3:06 AM
Nishanth
Nishanth - avatar