连接或合并字符串 (JAVA) [英] Concatenate or Merge strings (JAVA)

查看:65
本文介绍了连接或合并字符串 (JAVA)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在java中将一个字符串连接或合并到另一个字符串?例如我有第一个字符串:

How can I Concatenate or Merge a string after another string in java? for example I have this first string:

String1="12345"

这是第二个字符串:

String2="00000"

如何在第一个字符串之后连接第二个字符串?输出为:

How to concatenate the second string after first string? Output is:

String3="1234500000"

推荐答案

您可以使用 + 运算符来连接它们.给你的变量小首字母:string1

You can use the + operator to concatenate them. Give your variables small first letters: string1

用于打印的加号运算符:

Plus operator for printing:

System.out.println(string1 + string2);

或者存储在第三个字符串(string3)中

Or store in a third String (string3)

string3 = string1 + string2;

string1.concat(string2) 函数,但如果有 Null 值,它将 NPE.此外,concat() 方法只接受字符串值,而 + 操作符会默默地将参数转换为字符串(使用 toString()对象的方法)请参阅此处了解有关 Concat 和 + 的更多信息

There is the string1.concat(string2) function, but if there is a Null value it will NPE. Furthermore, the concat() method only accepts String values while the + operator will silently convert the argument to a String (using the toString() method for objects) See here for more on Concat and +

这篇关于连接或合并字符串 (JAVA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆