[Java SE] String connection

Source: Internet
Author: User

Java supports a variety of string connection methods, summarized as follows:

Package Cn.spads.tool.string;import java.text.messageformat;/** * <b> Test String Connection </b><br> * @ Authorsurmounting * @versionV1.1.0 * History * 1.1.0, September 1, 2015 surmounting first Edition * @sinceJava 6.0 */public class Teststringcon nect {public static void main (string[] args) {//Use string Connector System.out.println ("Today is" + 2015 + "Year" + 9 + "Month" + 1 + "Day");//Use S TringBuilderSystem.out.println (New StringBuilder ("Today is"). Append. Append ("Year"). Append (9). Append ( "Month"). Append (1). Append ("Day"));//Use STRINGBUFFERSYSTEM.OUT.PRINTLN (New StringBuffer ("Today is"). Append D ("Year"). Append (9). Append ("month"). Append (1). Append ("Day"));//Use STRING.FORMATSYSTEM.OUT.PRINTLN (String.Format ("Today is%s year S month%s Day ", 2015, 9, 1);//Use MESSAGEFORMAT.FORMATSYSTEM.OUT.PRINTLN (Messageformat.format (" Today is {0} years {1} months {2} days "," 2015 "," 9 " , "1"));//use String.Concat to connect only the string System.out.println ("Today is". Concat (""). Concat ("Year"). Concat ("9"). Concat ("month"). Concat ("1"). Concat ("Day"));}}

  

[Java SE] string connection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.