请教concat的用法:

bluestar_may 2004-08-11 09:05:43
那位帮帮忙解释一下concat的用法,谢谢了!
...全文
1042 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
SuperKnight 2005-03-16
  • 打赏
  • 举报
回复
public static voi main(String[] args){

String s="Java";

String s2=s;

s2+="Sun";

// s.concat("Java");

System.out.println(s2+s);

}
结果 也是
JavaSunJava
做何解释???
bluestar_may 2004-08-13
  • 打赏
  • 举报
回复
谢谢4位!!哪天在线等了好长时间,看着自己的问题慢慢沉到水底,郁闷了半天!

现在明白了,concat和“+”的作用吧!

public static voi main(String[] args){

String s="Java";

String s2=s;

s2+="Sun";

s.concat("Java");

System.out.println(s2+s);

}
它打印的结果应该是:JavaSunJava

几位英雄谢谢了!
foxty 2004-08-11
  • 打赏
  • 举报
回复
String str = "12";
str.concat("123");
//str <- "12123"
registered 2004-08-11
  • 打赏
  • 举报
回复
其实更简便的方法是
String s = "Oh ";
s += "Hello " + "World ";
c 语言里面这个函数(strcon)很有用
java 里我基本没用过...
iversonxk 2004-08-11
  • 打赏
  • 举报
回复
楼上的说的很详细啦
我也没什么可说的了,算是复习了一遍
dropship 2004-08-11
  • 打赏
  • 举报
回复
public String concat(String str)Concatenates the specified string to the end of this string.
If the length of the argument string is 0, then this String object is returned. Otherwise, a new String object is created, representing a character sequence that is the concatenation of the character sequence represented by this String object and the character sequence represented by the argument string.

Examples:

"cares".concat("s") returns "caress"
"to".concat("get").concat("her") returns "together"
Parameters:
str - the String that is concatenated to the end of this String.
Returns:
a string that represents the concatenation of this object's characters followed by the string argument's characters.
Throws:
NullPointerException - if str is null.

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧