Saturday, May 5, 2018

Java String trim() method with Example

String trim():- This method return same string with removing leading and trailing spaces. It checks the unicode value before and after string. If it exists then remove it and return string.

Syntax:-

public String trim()

Example:-

package JavaPkg;

public class TrimUse {
public static void main(String[] args) {

  String s1=" Java is a simple language      ";
  System.out.println(s1.trim());


}
}


Output:
Java is a simple language



                                                                            split() method in String
                                                                            toCharArray() method in String
                                                                            concat() Method in String




                                                                        

No comments:

Post a Comment