Trim, concat and intern a string

ReturnMethodSummary
Stringconcat(String str)Concatenates the specified string to the end of this string.
Stringtrim()Returns a copy of the string, with leading and trailing whitespace omitted.
Stringintern()Returns a canonical representation for the string object.

public class Main {
  public static void main(String[] argv) {
    String str = "java2s.com";
    
    str = str.concat("Java2s.com");
    System.out.println(str);
  }
}

The output:


java2s.comJava2s.com

  public class Main {
  public static void main(String[] argv) {
    String str = "     j a v a 2 s.com    ";
    System.out.println(">"+str+"<");
    str = str.trim();
    System.out.println(">"+str+"<");
  }
}
  

The output:

>     j a v a 2 s.com    <>j a v a 2 s.com<
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.