赞
踩
1.字符串连接(两种)
2.字符串比较
3.字符串截取
4.字符串查找
5.字符串替换
6.字符串与字符数组
第一种就是我们常用的 + 连接
public class Test { public static void main1(String[] args) { String str1 = "hello,"; String str2 = "my name is Tom!"; String str3 = str1 + str2; System.out.println(str3); } // 运行结果如下: // hello,my name is Tom! public static void main2(String[] args) { System.out.println(10 + 2.5 + "price"); // 先进行算术运算,再进行字符串连接 System.out.println("price" + 10 + 2.5); // 进行字符串连接 } // 运行结果如下: // 12.5price // price102.5 }
第二种就是String类提供连接两个字符串的方法concat( ),格式如下:
string1.concat(string2);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。