Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




trim() FUNCTION


trim() Function


The trim() Function is used to remove any leading and trailing whitespace from the String.


Example :



fun main() {

    var x = "   Hello  "
    var y = x.trim()
        
    println(y)
}


Output :



 Hello

In the above code, we have declared a String ' Hello ' with leading and trailing spaces.


var x = " Hello "

java_Collections

Then we have used the 'trim()' function to remove any unwanted spaces from beginning and end.


var y = x.trim()

java_Collections

Unwanted spaces are stripped out of it.