木其网络科技专业程序员代写http://www.xmsydw.com
程序员学历擅长经验网店链接
apenny硕士ASP.NET PHP 电子 通信设计 图像 编程 网络5年进入店铺
zheng_qianqian本科C语言 C++面向对象 Java5年进入店铺
guoguanl本科Java Web项目 JSP Hibernate Struts Mysql5年进入店铺

Java学习笔记——字符串常用函数

class JavaTest4_String {
	public static void main(String[] args) {

		String str1 = "IOS,ANDROID,BB,PALNM,WP,SYBIAN";
		String str2 = new String("Str2");
		char[] arr = {'S','t','r','2'}; 
		String str3 = new String(arr);
		String str4 = "         Jue          ";
		//长度
		System.out.println("长度");
		System.out.println(str1+"\t的长度为:"+str1.length());
		System.out.println(str2+"\t的长度为:"+str2.length());
		System.out.println(str3+"\t的长度为:"+str3.length());
		System.out.println(str4+"\t的长度为:"+str4.length());
		System.out.println();
		//拆分
		System.out.println("拆分");
		String[] strarr = str1.split(",");
		for(String s : strarr){
			System.out.print(s+"\t");
		}
		System.out.println();
		System.out.println();
		//查找
		System.out.println("查找");
		System.out.println(str1.indexOf("BB"));
		System.out.println(str1.indexOf("S"));
		System.out.println(str1.indexOf("ZZ"));
		System.out.println();
		//替换
		System.out.println("替换");
		System.out.println(str1.replaceAll("BB","CC"));
		System.out.println(str1.replaceAll(",","|"));
		System.out.println(str1.replaceFirst(",","|"));
		System.out.println();
		//返回字符串的副本,忽略前导空白和尾部空白
		System.out.println("返回字符串的副本,忽略前导空白和尾部空白");
		System.out.println(str4);
		System.out.println(str4.trim());
		System.out.println();
		//相等
		System.out.println("判断字符串相等");
		System.out.println(str2.equals(str3));
		System.out.println(str2==str3);
		System.out.println();

		//换大小写
		System.out.println(str1.toLowerCase());
		System.out.println(str2.toUpperCase());
		System.out.println();
		System.out.println();

	}
}
/*
---------- 运行 ----------
长度
IOS,ANDROID,BB,PALNM,WP,SYBIAN	的长度为:30
Str2	的长度为:4
Str2	的长度为:4
         Jue          	的长度为:22

拆分
IOS	ANDROID	BB	PALNM	WP	SYBIAN	

查找
12
2
-1

替换
IOS,ANDROID,CC,PALNM,WP,SYBIAN
IOS|ANDROID|BB|PALNM|WP|SYBIAN
IOS|ANDROID,BB,PALNM,WP,SYBIAN

返回字符串的副本,忽略前导空白和尾部空白
         Jue          
Jue

判断字符串相等
true
false

ios,android,bb,palnm,wp,sybian
STR2



输出完成 (耗时 0 秒) - 正常终止


*/

posted @ 2013-07-16 22:50  程序流程图  阅读(1796)  评论(0编辑  收藏  举报
木其网络科技专业程序员代写http://www.xmsydw.com
程序员学历擅长经验网店链接
apenny硕士ASP.NET PHP 电子 通信设计 图像 编程 网络5年进入店铺
zheng_qianqian本科C语言 C++面向对象 Java5年进入店铺
guoguanl本科Java Web项目 JSP Hibernate Struts Mysql5年进入店铺