string concat_Java String concat()方法与示例

string concat

字符串concat()方法 (String concat() Method)

concat() is a String method in Java and it is used to concatenate (add) a given string to the string. It returns a concatenated string.

concat()是Java中的String方法,用于将给定的字符串连接(添加)到字符串。 它返回一个串联的字符串。

Syntax:

句法:

    String str_object.concat(String str);

Here,

这里,

  • str is a String object to be added.

    str是要添加的String对象。

  • str_object is the main string in which we have to add/concatenate str.

    str_object是必须在其中添加/连接str的主要字符串。

Method returns a concatenated string at the end of the str_object.

方法在str_object的末尾返回一个串联的字符串。

Example:

例:

    Input: 
    str1 = "Hello"
    str2 = "world!"

    Function call:
    str1.concat(str2);

    Output:
    "Helloworld!"

Java code to concatenate the string using String.concat() method

Java代码使用String.concat()方法连接字符串

public class Main
{
    public static void main(String[] args) {
        String str1 = "Hello";
        String str2 = "world!";
        
        //adding str2 to the str1
        String str3 = str1.concat(str2);
        
        //printing values
        System.out.println("str1 = " + str1);
        System.out.println("str2 = " + str2);
        System.out.println("str3 = " + str3);
    }
}

Output

输出量

str1 = Hello
str2 = world!
str3 = Helloworld!


翻译自: https://www.includehelp.com/java/string-concat-method-with-example.aspx

string concat

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值