java的字符串数组_4.JAVA-数组、String详解

String str="hello world 我";char[] data = str.toCharArray(); //将String转为char

System.out.println(str.charAt(2)); //返回小标处2的char值,返回l

System.out.println(str.codePointAt(11)); //返回小标出11(“我”)的Unicode码

String str1= str.concat("是NQIAN"); //将str和"是NQIAN"进行连接,并返回给str1System.out.println(str1);

System.out.println( str.compareTo("hello.") ); //将"hello world 我"和"hello"按ASC表进行比较//如果str大于"hello."返回正数,相等返回0,小于返回负数System.out.println( str.compareToIgnoreCase ("hello.") ); //忽略大小写比较两个字符串System.out.println( str.contains("he") ); //判断str里是否包含"he"字符,包含返回true,否则返回falseSystem.out.println( str. startsWith("he") ); //如果str是以"he"开头,返回true,否则返回false

System.out.println( str.endsWith("he") ); //如果str是以"he"结尾,返回true,否则返回falseSystem.out.println( str.equals("hello world 我") ); //判断两个字符串内容是否相等,返回boolean类型

System.out.println( str.equalsIgnoreCase ("hello world 我") ); //忽略大小,判断两个字符串内容是否相等

System.out.println( str.format("str1:%03d %03f %s",75,5.234,"format") );

//类似于sprintf(),打印"str1:075 5.23400 format",需要注意:并不会改变对象本身内容,str的值还是为:hello world 我

System.out.println( str.hashCode () );//返回str的哈希值(内容不同的字符串,哈希值都不同)

System.out.println( str. indexOf ("e")); //从头查找出现e字符的位置,所以返回1,如果未找到返回-1

System.out.println( str. indexOf ("ld",4)); //从下标4处查找出现"ld"的位置并返回,如果未找到返回-1

System.out.println( str. lastIndexOf ("e")); //从尾部向前查找出现e字符的位置并返回,如果未找到返回-1

System.out.println( str. lastIndexOf ("o",5)); //从下标4处尾部向前查找出现"o"的位置,所以返回4

System.out.println( str. length ());//返回String长度

System.out.println( str. isEmpty ());//判断是否为空

System.out.println( str. replace("l","o")); //将字符串中的l替换为o,所以打印" heooo worod 我"String[] arrStr= str. split(" "); //以" "来拆开字符串,所以arrStr[0]="hello",arrStr[1]="world", arrStr[2]="我"

System.out.println( str. substring(1,5)); //返回str的内容下标1~4的串(不包括5),所以打印:ello

System.out.println( str.toLowerCase());//返回str的小写内容

System.out.println( str. toUpperCase());//返回str的大写内容

System.out.println(" adc ABC ". trim ()); //trim修剪字符串头和尾部的空格,所以打印:"abc ABC",注意:如果头尾的字符小于空格的话,也会被修剪掉的.

System.out.println( str.valueOf(true)); //返回true对应的字符串,也就是"true",当然valueOf也满足int,double等参数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值