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




String - trim() Method


String trim()


If there are any additional spaces in a String. trim() is used to delete those extra spaces.


Example :



public class Test{
	public static void main(String[] arg){
		String firstString = "      Hello     "; 
		    
		System.out.println("The trimmed String is : "+firstString.trim());
	}
}


Output :



  The trimmed String is : Hello

The trim() method removed all the additional spaces from the String "Hello".